You need to sign in to do that
Don't have an account?

Call external web service after DML operation in Apex
Hi,
I want to ask how to prevent this exception error ->
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
My case is to insert an object and use the id of the inserted object to be sent to external web service... But I got the exception error aboved, how do I manage to prevent this problem? Any suggestions would be great..
Thanx...
You'd have to use a Future method. I believe the official reason why you can't callout after a DML operation is that you would cause an inconsistent state if there was an error condition that rolled back the transaction (e.g. you submit an ID to an external source then a later error rolls back the transaction). Instead, place the callout in a Future method, and call that method instead.
All Answers
You'd have to use a Future method. I believe the official reason why you can't callout after a DML operation is that you would cause an inconsistent state if there was an error condition that rolled back the transaction (e.g. you submit an ID to an external source then a later error rolls back the transaction). Instead, place the callout in a Future method, and call that method instead.
Thanks for the suggestions.. It makes sense anyway, I will call the future method then..
Thanks a lot...