-3

Can anyone explain me how to stop recursive triggers with an example?

0

1 Answer 1

3

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 :

 public Class checkRecursive{ private static boolean check = true; public static boolean checkOneTime(){ if(check){ check = false; return true; } else{ return check; } } } 

Trigger :

trigger testTrigger on sObject(after update){ if(checkRecursive.checkOneTime()){ // Write Trigger Code/logic here } } 

I hope this will help you.!!!

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.