AfterUpdate
Runs in after update, after the records are saved and before the transaction commits.
Roles
- Writer: change other records or publish events through a unit of work.
- Dispatcher: make one bulk call per chunk, such as enqueueing a Queueable.
Register
Implement TriggerOrchestrator.AfterUpdate on the orchestrator and return the handlers from afterUpdateHandlers(). List order is run order. The trigger must list after update and call TriggerOrchestrator.run(new ContactTriggerOrchestrator()).
apex
public with sharing class ContactTriggerOrchestrator implements TriggerOrchestrator.AfterUpdate {
public List<AfterUpdate.Handler> afterUpdateHandlers() {
return new List<AfterUpdate.Handler>{ new ContactWriter(), new ContactDispatcher() };
}
}Rules
- Updating this object runs the update triggers again. Gate the predicate on a change, such as
isChangedTo, so the nested run skips the record. - A recursion depth of 3 is logged. When a record comes back to a handler that already acted on it 3 times in the transaction, the run logs an error and the handler keeps running. RecursionGuard sets its own depth and also skips the record there.
- Writer wins. A class that implements both roles runs only as a Writer.
- Called per chunk.
afterUpdateHandlers()runs for every chunk of up to 200 records, and each chunk commits its own unit of work.
WARNING
The trigger rows are read-only. Any write to them throws System.FinalException, and the update fails. Set fields in a BeforeUpdate.Populator.
