Activity Forums Salesforce® Discussions Why can we not perform callout in Salesforce after DML statement?

  • shradha jain

    Member
    July 4, 2018 at 8:28 am

    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.

  • Avnish Yadav

    Member
    September 7, 2018 at 12:51 pm

    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.

  • Parul

    Member
    September 13, 2018 at 4:52 am

    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

  • shariq

    Member
    September 14, 2018 at 1:35 am

    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.

Popular Salesforce Blogs