I have two objects A(parent) and B(child) related by a lookup relationship. I need to update records in object A using data loader. There is an after update trigger on object A which updates some fields on related records of object B. On object B as well there is an after update trigger which updates a field on parent object A. How can i handle recursion.
Asked
Active
Viewed 696 times
2
-
2Have you seen this post? – martin Sep 01 '15 at 13:03
2 Answers
1
You should be using a Static variable(preferably Boolean) in an Utility class to determine the state of the run of the trigger.
So add a check at the initial of the code to look for the Static variable to be true and execute the code in Object A trigger. Before updating Object B records make the Static variable false and do the update.
So when the Object B trigger updates Object A, the Object A trigger will check for Static variable and it will be false and skip the execution(updating Object B).
Please refer cookbook here.
Vigneshwaran G
- 6,129
- 3
- 22
- 39
-
http://salesforce-parth.blogspot.in/2015/09/recursive-trigger-class-in-salesforce.html – Parth Thakkar Sep 25 '15 at 16:43