function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aman wadhwa 18Aman wadhwa 18 

hello community some query about order of execution

Hi, 
I have a before update trigger on an account number field which increments the number field by 1 every time a record is updated or created new.
Also, a process builder on the same field and doing the same increments on the same field by one so when I put value "1" in that field it updates it to 4 so does that means trigger executes again after process builder updates that field 
Thanks in advance 
Best Answer chosen by Aman wadhwa 18
Andrew GAndrew G
Short version - yes. 

Longer version
1 is placed in the field.  
Save is pressed so the before trigger fires and updates the field to 2.
Your Process builder fires and updates the field to 3.  Since this is a DML, it fires the before trigger again.  From the reference Danish supplied:

When a process or flow executes a DML operation, the affected record goes through the save procedure.

So, the Trigger then updates to 4.

This one of the reason why when mixing Apex with PB and Flows, that you need to consider one option or the other , or when to disable the recursion of triggers by using booleans in the triggers.

regards
Andrew

All Answers

Danish HodaDanish Hoda

Hi Aman,
The flow of execution is as below in this context, Plz refer https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm for better understanding:

1) Before update
2) Update through Process Builder
3) the update by PB fires the update trigger again.

Andrew GAndrew G
Short version - yes. 

Longer version
1 is placed in the field.  
Save is pressed so the before trigger fires and updates the field to 2.
Your Process builder fires and updates the field to 3.  Since this is a DML, it fires the before trigger again.  From the reference Danish supplied:

When a process or flow executes a DML operation, the affected record goes through the save procedure.

So, the Trigger then updates to 4.

This one of the reason why when mixing Apex with PB and Flows, that you need to consider one option or the other , or when to disable the recursion of triggers by using booleans in the triggers.

regards
Andrew
This was selected as the best answer