What is the order execution in Salesforce?
It is all laid out in Salesforce’s Triggers and Order of Execution. Every type of trigger and action happens in a set order. What is not set is the order of execution of items of the same type such as a collection of Process Builders.
If your use case requires that a particular Process Builder gets executed before another one then you will need to control the sequence yourself. One option is to redo all Process Builders for a single object as invocable Process Builders and then call them in order from a controlling Process Builder.
Not wanting to recreate my Process Builders from scratch, I used a different technique to put two Process Builders in the order I wanted. I had the first Process Builder set a value that the second one looks for. The second Process Builder will not continue execution if the first hasn’t yet executed and set the value.
I have two Process Builders that I created to act on the Opportunity object. One contains most of the workflow I’m doing when the Opportunity record changes. The other one was only for updates I needed when the Opportunity record was created. This should be fairly straight forward except that the Record Update Process Builder was executing before the Record Create Process Builder.
I was able to resolve the sequence the Process Builders executed by first creating a checkbox field in my Opportunity that would default to checked when a record was created. Then my Opportunity Create Process Builder would clear the checkbox as its last action. My Opportunity Change Process Builder first tests the checkbox and only continues if it has been cleared.
- Create a custom field on the Opportunity object. The field type should be Checkbox with a default value of Checked. This field does not need to be on any page layouts.
- Add a final criteria step in the “Opportunity – Record Create” Process Builder. This just needs to execute the actions without testing for any criteria.
- Add an action to clear the checkbox field.
- Add a first criteria step in the “Opportunity – Record Changes” Process Builder.
- The criteria should check if the checkbox field is still checked.
- Continue on with the rest of the Process Builder only if the result is False.
With the new field added to Opportunity and the added steps in my Process Builders to test or clear the field, I am able to force my “Opportunity – Record Create” Process Builder to always execute before my “Opportunity – Record Changes” Process Builder when a new Opportunity record is created.
You probably noticed that the first Immediate Action in my Record Update Process Builder says “Do Nothing”. Read my next post to find out how to tell your Process Builder to do nothing.
5 thoughts on “How to make one Process Builder execute before another Process Builder”
When i tried implementing the same to sequence the order, PB-1 dint run , PB-2 started and checked that value is not set to ‘True’ yet and dint enter to PB-2. Transaction got over, it dint go back to PB-1 again. So eventually both PB dint run.
Am i doing something wrong!
The Record Change PB needs to be set to run recursively.
I just consolidated all of our PBs into a single one per object and control the order that way and it seems to be working so far.
LikeLiked by 1 person
Eddie’s suggestion is the best option. Then you can arrange the nodes within the PB in the order they should fire. Recursive can cause issues.
LikeLiked by 1 person