2

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.

Walker
  • 2,333
  • 4
  • 34
  • 73

2 Answers2

2

Take a look here. It besically suggests to use static variable to determine if we have to execute the trigger or not.

Abbas
  • 675
  • 7
  • 19
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