Hello Guys, Few days back, I was working on triggers and faced one problem that too many soql queries. But in real, I didn't use more than 2 queries in trigger. That mean the trigger was calling itself by more than one time. In other words it was recursive trigger.
So today, I'm gonna show you that how to avoid recursive triggers.
First of all you have to make sure that your trigger is executed just one time. For doing this, you have to make one class and add static boolean variable with default value true in it.
In the trigger, before executing your code keep a check that the variable is true or not.
Once you check make the variable false.
Following is the code for that.
See, It's this much easy to avoid recursive trigger. I hope this will help you all. See you all guys later with some new problems and solutions.
So today, I'm gonna show you that how to avoid recursive triggers.
First of all you have to make sure that your trigger is executed just one time. For doing this, you have to make one class and add static boolean variable with default value true in it.
In the trigger, before executing your code keep a check that the variable is true or not.
Once you check make the variable false.
Following is the code for that.
Class Code :
Trigger Code :
See, It's this much easy to avoid recursive trigger. I hope this will help you all. See you all guys later with some new problems and solutions.
No comments:
Post a Comment