0

I have the following process triggering when an Opp generates an Order:

  1. Opp -> Order (Draft status)
  2. Platform Event Trigger (based on Order Status change)
  3. PE Flow Subscriber: Sets Order Status to Order Received
  4. Process Builder A (IF Order Status = Order Received) - Check if Order should be automated and tick 'Auto' checkbox if is.
  5. Process Builder B (IF 'Auto' field = TRUE) - Auto process the order

The problem I have is that everything is fine up to 4), however, 5) is being checked once and not actioning. If I activate recursion on 5) then it works. And it also works if I convert 4) into a platform event subscriber...

But I want to understand why it's not working, please. I've checked a number of 'Order of Execution' guides but it's still not helping. Thanks for your help.

1
  • if you are going to refactor the PBs, you might as well move to Flows as Flows are the way of the future in SFDC, flow could be named On Order Update and (your choice) be a before save or after save flow
    – cropredy
    Commented May 4, 2021 at 16:38

2 Answers 2

2

Each phase of automation (Workflow, Flows, and Process Builders) are designed in a way so as to simulate parallelism (e.g. as if all elements executed simultaneously). That means that each Process Builder gets the same, pre-modified version of the record, even if they "modify" the record.

More specifically, each element is first evaluated, any actions that are met will be queued for execution, and then all actions are executed only after all elements are done.

This pseudocode attempts to explain how this looks internally:

ProcessBuilderAction[] queue = new ProcessBuilderAction[0];
for(ProcessBuilder element: getProcessBuilders()) {
  for(ProcessBuilderStep step: element.getSteps()) {
    if(step.shouldExecute()) {
      queue.add(step.actionsToExecute());
    }
 }
 for(ProcessBuilderAction action: queue) {
   action.execute();
 }

This is why you need the recursion feature enabled to make it work. Without it, the second Process Builder doesn't get to see the changes.

0

It's not working because you can't guarantee that process builders will fire in any particular order. That's why it's always recommended that there is only one process builder per object.

2
  • So are the process builders running in the same transaction and, because the PB which is setting the checkbox to TRUE is always running second, it never fires? If that's the case then why then does enabling recursion on 5) make it work? Thanks for the reply, btw. Commented May 4, 2021 at 14:28
  • 5 is probably running before 4, but can't be certain because we can't predict the Order that PBs execute in. Enabling recursion makes 5 work because it's executing again when 4's update action runs. However, that's not the correct way to fix this. The correct way would be to combine the two PBs. You may want to put criteria for 5 in a flow and call it from the relevant existing node in 4, so that the Checkbox is checked and the order is processed. Then you can add an additional node to the process builder so that the order also gets processed if the checkbox is checked manually. Commented May 4, 2021 at 15:26

You must log in to answer this question.

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