How to stop Recursion Trigger Calls In Salesforce

by Rijwan Mohmmed
2 comments
how-to-stop-recursion-trigger-calls-in-salesforce

Recursion occurs when the same code is executed again and again. Due to this, an error is populated maximum trigger depth is exceeded.

We can stop this by creating a static variable. With this variable trigger, code execute one time.

Apex Trigger:

trigger ContactTrigger on Conatct(before insert) {

    if(ContactTriggerHelper.runOnce){
        ContactTriggerHelper.runOnce = false;
        // trigger logic
    }   
 
}

Apex Helper Class:

public class ContactTriggerHelper { 
   public static boolean runOnce = true; 
}

You may also like

2 comments

Darci November 8, 2021 - 8:50 am

It’s fantastic that you are getting thoughts from this paragraph as well as from our dialogue
made at this place.

Reply
Deltax November 8, 2021 - 8:56 am

Thanks for feedback 😊

Reply

Leave a Comment