Salesforce supports seven trigger events in total — a combination of two timings (before, after) and four DML operations (insert, update, delete, undelete). You declare any combination you need in the trigger signature, and Salesforce calls your code at exactly those moments.
The seven events
| Event | Fires when | Trigger.new | Trigger.old |
|---|---|---|---|
before insert | Records about to be inserted | Yes (writable) | No |
before update | Records about to be updated | Yes (writable) | Yes |
before delete | Records about to be deleted | No | Yes |
after insert | Records just inserted | Yes (read-only) | No |
after update | Records just updated | Yes (read-only) | Yes |
after delete | Records just deleted | No | Yes |
after undelete | Records restored from Recycle Bin | Yes (read-only) | No |
Two events you might expect — before undelete and any merge event — don’t exist. The platform handles merge by firing standard delete and update events on the losing and surviving records.
Declaring multiple events on one trigger
trigger ContactTrigger on Contact (
before insert, before update, before delete,
after insert, after update, after delete, after undelete
) {
new ContactTriggerHandler().run();
}
Inside the trigger, branch on Trigger.operationType or the Trigger.isInsert / isUpdate / isDelete / isUndelete and Trigger.isBefore / isAfter booleans to route to the right logic.
Picking the right event
- Set defaults or validate before save? Use
before insertand/orbefore update. You can mutateTrigger.newdirectly — no DML required. - Create child records that reference the parent’s Id? Use
after insert— the new records have IDs only after insert. - Block a deletion? Use
before deleteand callrecord.addError(...). - Roll up changed values to a parent record? Use
after update, compareTrigger.newagainstTrigger.oldMap, and update parents in bulk. - Re-derive a calculated field on restore? Use
after undelete.
Common interview follow-ups
- Is there a
before undeleteevent? — No. The platform only exposesafter undelete. - What fires when a record is merged? — Standard
deleteevents on the losing records andupdateon the master. There’s no dedicated merge event. - Can one trigger handle multiple events? — Yes, and the “one trigger per object” best practice depends on it.
Verified against: Apex Developer Guide — Trigger Syntax. Last reviewed 2026-05-17 for Spring ‘26.