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;
}
2 comments
It’s fantastic that you are getting thoughts from this paragraph as well as from our dialogue
made at this place.
Thanks for feedback 😊