I have a requirement where, on changing a particular field value of an account record from Lightning page layout, I have to make a callout. If the response from the callout is not successful, then the record shouldn't be saved, and it should display an error message.

Here, I am using Process Builder and using the invocable method, I am calling a REST API. In this case, I am getting this error message:

'You have uncommitted work pending. Please commit or rollback before calling out'.

But if I use a future call, then it will be a new transaction; the record will always save irrespective of the success or failed response.

How can I achieve this requirement criteria to make it look like a synchronous transaction? Appreciate your inputs.

1 Answer 1


You will need to implement this validation on the front end, using a Visualforce page or Lightning component. Your custom UI - perhaps an override of the Edit action - can make a callout to validate data input prior to initiating DML at all. You then have full freedom to interact with the user's active browser session based upon the response from your web service, be that by displaying errors, showing a Toast message, highlighting problem fields, or what have you.

Once the DML operation has begun, you cannot make a callout within the same transaction. The platform will not allow you to keep a database transaction open while waiting for a callout's response. See this question for details.

  • 1
    +1 Took the words right out of my textarea :p
    – sfdcfox
    Sep 20, 2019 at 2:40
  • Although, just realized, I also had this link you might include to an Idea. Probably won't happen, but couldn't hurt.
    – sfdcfox
    Sep 20, 2019 at 2:44
  • Is there any way to override the Save button in a standard page layout? As per your response, I believe, we have to build a custom layout.
    – nica
    Sep 20, 2019 at 2:54
  • @snl You will need to do some species of front-end development. You can't override the Save button on a standard page layout.
    – David Reed
    Sep 20, 2019 at 3:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .