Development questions
What happens if you try to modify Trigger.old in any trigger event?
Trigger.old and Trigger.oldMap are always read-only. Attempting to change a field on them throws a runtime error: Record is read-only. Use them only for comparison with the new values, or to know what is being deleted.
apex-triggertriggercontext-variables
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?