How to avoid the recursive triggers in Salesforce

|
| By Webner

Recursive Trigger:-

When a trigger is calling itself again and again, this situation is called a recursive trigger, or we can say that a recursive trigger performs the same process multiple times. If we don’t handle this recursive trigger, it can hit the Salesforce governor limits.

How to avoid recursive trigger:-

We can avoid a recursive trigger by creating one class with one boolean variable and setting the value as true now in the trigger before executing the trigger we need to check the value of the boolean variable which we have created in our class if the value is true it will execute the trigger once its go in trigger execution part then we have to make the boolean variable false by doing this our trigger will execute only once.

Example:-
Apex class
public class checkRecursiveTrigger {
Public static Boolean triggerFlag=true;
}
Apex Trigger
Trigger Test on contact (after update) {
if(checkRecursiveTrigger.triggerFlag) {
checkRecursiveTrigger.triggerFlag = false
// trigger code
}}

Leave a Reply

Your email address will not be published. Required fields are marked *