Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Asynchronous calls and DML
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Asynchrono us calls and DML
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-02-2013 11:45 AM
I have a simple logger framework for creating logs for certain actions. I started getting "You have uncommitted work pending" due to a callout occuring after I inserted a new log entry. The board suggestions for solving the problem specified using future calls for the callout. The failing callout is called by a VF page that is displayed after the log is written. There is no relationship between the log entry and the subsequent call.
I didn't read anything forbidding an insert statement in a future call, so I use the future call for insert the log entry. When I executed again, I got the same error. This was puzzling, so I edited out the code where I execute the insert and ran again and I still got the same errror.
Obviously I don't understand what is really happening. Does a @future Apex job create a "transaction", or in some other way prevent subsequent callouts?
Any suggestions for alternate approach is appreciated.
Re: Asynchrono us calls and DML
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-02-2013 01:21 PM - edited 01-02-2013 01:22 PM
If you make a DML statement (insert, upsert, delete, etc) then you can't make any callouts after that statement.
Simply put, make all of your callouts first and then do all of your DML after. Even then, you are limited to 10 call outs per @future call / run.
You can't make an explicit commit call to the database, apex does that for you after your class execution ends. The commit call sends the work / DML command to the database. This is why your error message is telling you that you have uncommitted work pending.
Salesforce.com Certified Advanced Administrator
http://www.forcedisturbances.com/

