What is a Trigger Framework and how do you prevent recursive triggers?
Suggested answer
A Trigger Framework separates trigger logic from the trigger itself via a handler class. Pattern: one trigger per object, all logic in a handler class. The trigger only calls handler methods: handler.beforeInsert(Trigger.new); Benefits: testability, maintainability, single entry point. Preventing recursion: When a trigger updates a field, which fires another trigger, creating an infinite loop. Solutions:
1. Static Boolean flag: A static variable (TriggerHandler.firstRun = false) set to false after the first execution, preventing re-entry. Check it at the start of the handler.
2. Static Set of IDs: Track which record IDs have been processed in this transaction and skip them if seen again.
3. Use ISCHANGED() in flow criteria to prevent re-firing. Frameworks like fflib and Dan Appleman's pattern provide this natively.
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.