Development questions
What is a Recursive Trigger and how does it cause the Maximum trigger depth exceeded (limit: 16) error?
A recursive trigger is one whose logic performs DML that causes the same trigger (or another trigger that updates back) to fire again, repeatedly.
Example: an after update trigger on Account updates Accounts, which fires the after update trigger again, and so on. Salesforce allows trigger nesting only up to depth 16; beyond that it throws Maximum trigger depth exceeded and rolls back the transaction.
Prevent it with a static Set of processed Ids, by checking that field values actually changed, or by moving same-record changes into before triggers.
apex-triggertriggerrecursion
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?