+ 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:

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

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

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).


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.