A developer writes a trigger on the Account object on the before update event that increments a count field. A workflow rule also increments the count field every time that an Account is created or updated. The field update in the workflow rule is configured to not re-evaluate workflow rules.
What is the value of the count field if an Account is inserted with an initial value of zero, assuming no other automation logic is implemented on the Account?
Correct Answer: D
The value of the count field after inserting an Account with an initial value of zero is 2, because both the trigger and the workflow rule will increment the count field by 1. The order of execution for this scenario is as follows:
* The Account record is inserted with a count value of 0.
* The system runs the before insert trigger, which increments the count value to 1.
* The system saves the record to the database, but does not commit yet.
* The system runs the after insert trigger, which does not affect the count value.
* The system executes the workflow rule, which increments the count value to 2.
* The system updates the record again with the new count value.
* The system commits the record to the database.
The field update in the workflow rule is configured to not re-evaluate workflow rules, which means that the workflow rule will not be triggered again by the second update. Therefore, the count value will remain 2.
References: Triggers and Order of Execution, Workflow Field Updates, Learn Salesforce Order of Execution
Recent Comments (The most recent comments are at the top.)
The explanation is wrong - since in question we get only before update trigger, the workflow rule changes the field to 1 first and then before update trigger is called