You need to sign in to do that
Don't have an account?
charchit nirayanwal
Can We Perform Callout After DML Operation?
The clear answer is No.
Reason Behind ?
Reason Behind ?
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Recommend reviewing https://salesforce.stackexchange.com/a/301292/80089 according to which
If you make a DML operation, salesforce opens a thread to database or takes one from pool when available.
If the transaction is successful, data is committed and thread is closed.
If the transaction fails, the data is rolled back to previous state and thread is closed.
But when you do a callout, salesforce needs to keep a thread open till the transaction is complete. This is clearly a problem because in worst case scenario the thread has to remain open for 120 seconds (Max timeout of a callout).
Consider this in a multi tenant environment where millions of requests are executed. Keeping a thread open for long time will choke other operations on the database resulting is adverse performance issues.
That is why you aren't allowed to make a callout after DML.
Related: https://help.salesforce.com/s/articleView?id=000328873&type=1
If this information helps, please mark the answer as best. Thank you
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”.
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
The Apex Callout Delegator can make the impossible; possible! That is how to perform a Callout after a DML.
"The Callout Delegator performs callouts in a separate context, much like @future and Queueable, but with the key difference of being synchronous. "
https://www.soliantconsulting.com/blog/apex-callout-delegator/