function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Baz DensonBaz Denson 

Process Builder @InvocableMethod You have uncommitted work pending. Please commit or rollback before calling out

I have an Apex method which creates a new record in Xero (accounting software).

I am trying to make the Invokable so I can use process builder to create a new Xero record when an account is created in Salesforce.

I am getting the 'You have uncommitted work pending. Please commit or rollback before calling out'

I kind of understand the reason for the error, I can't have a callout after a DML operation, but I'm unsure how to resolve it. How can I get process builder to do the callout before the DML operation when thats the trigger for the Apex to run.
Maharajan CMaharajan C
Hi Barry,

Refer the below Links:
http://ashishkeshari.com/index.php/2017/05/11/dml-before-apex-callouts-using-salesforce-ajax/
https://help.salesforce.com/articleView?id=000003701&type=1
https://salesforce.stackexchange.com/questions/115434/how-to-solve-callout-error-you-have-uncommitted-work-pending-please-commit-or
https://salesforce.stackexchange.com/questions/159138/what-can-cause-system-calloutexception-you-have-uncommitted-work-pending-plea
https://thysmichels.com/2017/03/14/apex-workaround-for-doing-callout-after-dml-please-commit-or-rollback-before-calling-out/

Can you please Let me know if it works or not!!!

If it helps don't forget to mark this as a best answer!!!

Thanks,
​Raj
Baz DensonBaz Denson
Hi Raj

Thanks for that response, but not of them specifically relate to process builder. 

I am not trying to create an account in Apex, the creation of the account is the trigger in Process Builder to run the invocable Apex (which pushes a new account to an external accounting package).

Thanks 

Barry
Andrew Lambert 8Andrew Lambert 8
Hi Baz,
Did you end up finding a solution? 
I'm encountering the exact same issue. I have invocablemethod Apex code written to action a reverseGeocode and return the address.
Since adding to ProcessBuilder or Flow executing when record meets criteria I get the DML issue, despite my code not actually including any DML actions.

My working assumption is that despite it being a separate called method, it treats it as part of the triggering ProcessBuilder / Flow update/save event and actions AFTER any other actions or triggers which essentially makes it impossible to do from what I can see. 

I've even tried putting it into a scheduled flow to avoid any existing updates etc being triggered and dropping straight into the Apex method but gave the same error.