Transaction-scoped recursion guard
A guard that stops an automation from re-firing on its own write, scoped to the transaction and keyed to what actually changed, so a save runs the logic once instead of looping into the governor limit.
WhenAny after-save flow or Apex trigger that updates a field on the same object it fires on, or touches a related record whose automation writes back. The tell is intermittent CPU-limit save failures that only appear under bulk load.
- Do it right
- In Apex, a static Boolean or a static Set of Ids in a helper class; statics persist for the transaction and reset between transactions.
- In Flow, guard with entry criteria (ISCHANGED on the driving field, plus a check that the field is not already at its target value), since Flow has no static variable.
- Gate on the field that actually changed, not a blunt already-ran flag, so legitimate later updates in the same save still process.
- Keep same-record field writes in before-save, which never triggers a second save and cannot recurse.
The point of the guard is to run the logic exactly once per record per save, not once per transaction; a boolean answers the wrong question and drops records, and misplacing the logic means you are guarding a problem you created by choosing the wrong timing.