Skip to content

AfterUpdate

Runs in after update, after the records are saved and before the transaction commits. Both the old and the new values are available. Change other records with a Writer, or hand bulk and async work to a Dispatcher.

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.

Add-ons

  • ParentQuery: load parent (lookup) fields before the first handler runs; read them with getNewParent.
  • PriorParentQuery: load the parent the old row pointed to; read it with getOldParent.
  • RelatedQuery: query children, siblings or any other records once per chunk; read them with getRelated.
  • OwnUnitOfWork: give the handler its own unit of work, committed right after it. Writer only.
  • Bypassable: skip this handler for the whole chunk when a condition holds.
  • RecursionGuard: cap how many times this handler acts on the same record in one transaction (default 3).
  • Finalizer: run once after this handler’s records, with the records that qualified.
  • ContinueOnError: log and swallow this handler’s exceptions, so the save goes on.

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() };
    }
}

Good to Know

  • Read-only rows. Any write to the trigger rows throws System.FinalException, and the update fails. Set fields in a BeforeUpdate.Populator.
  • Updating this object runs the update triggers again. Gate the predicate on a change, such as isChangedTo, so the nested run skips the record.
  • Recursion limit of 3. Each handler acts on the same record at most 3 times per transaction. Change the limit with RecursionGuard.
  • 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.