How do governor limits interact in complex trigger chain scenarios? What mitigation strategies do you use?
Suggested answer
Trigger chain scenario: A trigger on Object A performs DML on Object B, which fires a trigger on Object B, which DMLs Object C, etc. All of these execute within the same transaction and share the same governor limits (100 SOQL queries, 150 DML statements, 12 MB heap). Deep trigger chains can rapidly exhaust limits.
Mixed-save context: When different object types are DML'd in the same transaction, limits are shared. This is common in triggers that update related objects.
Mitigation strategies:
1. Recursion prevention: Use a static Boolean or a static Set to prevent the same trigger from firing multiple times for the same records in one transaction.
2. Bulkify all DML and SOQL: Collect records into Lists/Maps; perform a single SOQL/DML outside loops.
3. Async offloading: Move non-critical operations to Queueable Apex or Platform Events to avoid hitting limits in the primary transaction.
4. Limit trigger chain depth: Design the data model to minimise cascading DML across many objects.
5. Monitor with Apex logs and Limit debug level: Use Limits.getQueries() / Limits.getDMLStatements() in debug statements to catch near-limit scenarios in testing.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.