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

calling webservice in future handler from a trigger | Error | System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
Hello,
I have following error:
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
My usecase:
I am calling a webservice in a future handler.
Other workaround i tried:
I tried to call the webservice without a future handler, but as i am calling in trigger it is giving me error.
Can someone please tell me any workaroud ?
thank you
I have following error:
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
My usecase:
I am calling a webservice in a future handler.
Other workaround i tried:
I tried to call the webservice without a future handler, but as i am calling in trigger it is giving me error.
Can someone please tell me any workaroud ?
thank you
Please follow below code:-
Kindly mark my solution as the best answer if it helps you.
Regards
Mukesh
All Answers
Please follow below code:-
Kindly mark my solution as the best answer if it helps you.
Regards
Mukesh
Could you please check and confirm if there any DML statements before your callout? You would need to put all DML statements after your callout or you would need to do the callout in a different context altogether.
Please see this help article for resolution : https://help.salesforce.com/articleView?id=000079772&type=1
Thanks!
Satyajeet
More info on this issue check below links :
https://help.salesforce.com/articleView?id=000003701&type=1
https://help.salesforce.com/articleView?id=000079772&type=1
https://salesforce.stackexchange.com/questions/115434/how-to-solve-callout-error-you-have-uncommitted-work-pending-please-commit-or
If you have still had issue please provide your sample code.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
This exception occurs when a record is in transaction of some DML and you try to make a callout using the same record.
Since your record is not commited to the database still, you will not be able to process the record asynchronously(future callout). Your trigger would be still processing the record and in between you would have invoked the future method and this leads you to face the exception.
You can place the future call at the end or try creating a @invocable function and later process the webservice callout through process builder while all your triggers would have successfully executed by that time!
Thanks.
Hello All,
thank you for suggestion.
Just to give more information, there are around 10 trigger and few process builder on the Asset object.
It is not possible to paste the code as its too big and security concerns.
I totally agree with the exception. but i am finding a workaround which will not affect the exsisting functionalities.
I will try to implement the Gautams idea.
in my case, Trigger webservice (in future handler ) and updating Asset object.
Working for few records, when we do bulk load, I am running into same issue.
I struck with same issue for a long time, did you get any solution for this?