I am trying to make api callout from the invocable method. I know that api call in trigger is not allowed ( directly in trigger context ) as it could hold the database transaction for longer time. Same I can assume with invocable methods because those are going to get executed as the part of complete DML lifecycle.

Now what I have done differently here is that instead of invoking the apex invocable method immediately, I scheduled it like 0 hours after CreatedDate, just to make sure that it goes through different transaction and I would be able to avoid the uncommitted work pending error.

Here is the setup that I have done:

  1. Wrote a invocable method which is making api call using the account details.
  2. Configured the process builder to schedule the invocable method to be invoked after 0 hours after the CreatedDate of account.

When I checked the logs the 2 different transactions are happening:

  • One where the account is created and it is logged under my user (admin).
  • Second one is of the invocable method by "Automated Process" user.

Grabbed the logs of second debug and there is no DML activity in whole transaction, since I am getting uncommited work pending.

enter image description here

Now the question is since the invocable method is getting a different context there is no DML activity before then why does salesforce is giving uncommitted work pending error. Is there anything which I am missing?

1 Answer 1


The Scheduled Action is itself a DML transaction. The "zero" used DML shown is because the top level DML in a transaction is "free" (it never counts towards the limits). Try inserting a record against an object withno triggers or actions, you'll see the same type of log.You need to instead use a future or Queueable class to execute asynchronously.

  • Thats a bummer, I thought we could get creative here if this could have worked. Thanks for reply. Apr 8, 2020 at 6:48

You must log in to answer this question.

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