Activity › Forums › Salesforce® Discussions › Why can we not perform callout in Salesforce after DML statement?
Tagged: Apex Callouts, DML Operation, DML Statement, Salesforce Apex Code, Salesforce Code, Salesforce Records
-
Why can we not perform callout in Salesforce after DML statement?
Posted by madhulika shah on July 4, 2018 at 8:20 AMWhy can we not perform callout in Salesforce after DML statement?
shariq replied 7 years, 8 months ago 5 Members · 4 Replies -
4 Replies
-
We cannot perform callout after DML statement because callout will take time to return and salesforce does not wait to write or update records in database.
- [adinserter block='9']
-
Hello,
The execution sequence of a DML operation is very well controlled and planned for in the context of the transaction. Allowing a callout in the middle usually (but not always), the code can be re-organized such that you are working with in-memory objects until after the call out, then execute the DML so we cannot perform callout in salesforce after DML statement.
Thanks.
-
Hi
The DML operation perform a transaction it return the data after performing transaction completly so if you perform callout in the middle it may affect in the result. It’s true that you cannot make callouts with pending transactions in the request context. Also, it’s not possible to do an explicit commit. So your only way out is to make the callout in a separate context. I understand that asynchronous call using @Future doesn’t work for you.
Thanks
-
Hi,
Callouts aren’t allowed after DML operations in the same transaction because DML operations result in pending uncommitted work that prevents callouts from executing.
Since Salesforce does not have a explicit Commit, if you try doing DML and then Callout, you will get ‘You have uncommitted work pending. Please commit or rollback before calling out”.
Hope this helps.
Log In to reply.