+ Start a Discussion

Recursive triggers


I have a situation in which a @future method called by 2 trigger is called recursively and I get a ' @future cannot be called from a @future method'


Is there a way to avoid this. I learnt that static variables can be used but I dont know how to use it correctly  





Assume you have a class with static:


public class myClass {

public static Boolean running= false;



The in your trigger you have code like:


   if (!myClass.running) {   // will run first time obviously !

   // call future method



Your future method


public String myFuturemethod(params) {

    myClass.running = true; // will stop the trigger calling the future again

    // code that fires trigger



I think that will do it !