How to avoid the recursive triggers in Salesforce

Author - Webner
26.12.2022
|
0 Comments
||

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
}}

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published.