0

Referring to the Triggers and Order of Execution documentation. It is known that, before-save flow -> before trigger -> after trigger -> after save flow.

My main question here revolves only on two of the above:

  1. before trigger
  2. after save flow

The after save flow is not running as expected in my case, which is; as described below:

Preface
To do this experiment, I have created a new custom object called Execution_Order__c and wrote the following apex trigger:

trigger ec on ExecutionOrder__c (before insert, before update) {
    for (ExecutionOrder__c e : trigger.new){
        e.name = 'I am from trigger';
    }
}

and I have an after save flow as seen below: Entry criteria for flow Update the record with new name

According to my understanding, first when I update this record and click save (standard edit and save ui), the record's name will be changed as specified in the trigger. Then, once everything is done, the after save flow should update this record's name to whatever typed in flow.

However, this is not the behaviour, instead, every single update operation populates the Name field as written in the trigger.

Can anyone enlighten me on this behaviour please?

1 Answer 1

2

If you read Triggers and Order of Execution carefully, you'll see that this is expected. First, the before save trigger executes as expected. Then, the after save flow process updates the record recursively, which triggers the trigger a second time. Because this is a recursive update, the flow doesn't run a second time. This is because:

During a recursive save, Salesforce skips steps 9 (assignment rules) through 17 (roll-up summary field in the grandparent record).

This rule is in place to prevent infinite recursion between triggers and flows.

1
  • Absolutely eye opening! Many thanks master fox!
    – prem22
    Feb 15 at 4:48

You must log in to answer this question.

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