BeforeDelete
Runs in before delete, before records are removed.
Roles
- Validator: block a delete with
addError. - Writer: change other records or publish events through a unit of work.
Register
Implement TriggerOrchestrator.BeforeDelete on the orchestrator and return the handlers from beforeDeleteHandlers(). List order is run order. The trigger must list before delete and call TriggerOrchestrator.run(new ContactTriggerOrchestrator()).
apex
public with sharing class ContactTriggerOrchestrator implements TriggerOrchestrator.BeforeDelete {
public List<BeforeDelete.Handler> beforeDeleteHandlers() {
return new List<BeforeDelete.Handler>{ new ContactValidator(), new ContactWriter() };
}
}Rules
- Writes land before the delete. The shared unit of work commits after the last handler, while the rows and the records that point at them still exist.
- Cascade deletes fire no child triggers. Records removed by a cascade delete, such as an account's contacts, do not run their own delete triggers. Read them here with a RelatedQuery.
- Merges look like deletes. The records that lose a merge fire before delete like a plain delete.
MasterRecordIdis set only in AfterDelete. - One role per class. A class that implements both roles runs only as a Validator.
