Development questions
Why do we use after undelete triggers, and why doesn't before undelete exist?
After undelete triggers run when records are restored from the Recycle Bin. Use them to rebuild related data, e.g. recalculate roll-ups, restore related child links, or notify admins.
There is no before undelete because restore is not an edit of the record: the record already exists with its stored values, so there is nothing to modify or validate beforehand. Records in Trigger.new for undelete are read-only, and Ids are available.
apex-triggertriggerundelete
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?