function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MDXHikerMDXHiker 

Trigger on insert and update

I have a trigger which is fired on insert and update. The trigger modifies few few fields on a std object.

There also workflow rules on the std object with field updates. Now this is fires the trigger once again. So I have the trigger firing twice. What is the way around this?

Has nayone worked around this ? Thanks
TehNrdTehNrd
What you can do is create a class that holds boolean variables that indicate if your trigger has executed.

Code:
Class:

public class flowControl {
  
  //---------------------------Application Automation Trigger Control--------------------------
  public static boolean runApplicationAutomation = true;
  
  //Return the run trigger boolean   
  public static boolean runApplicationAutomation(){
   return runApplicationAutomation;
  }
  
  //Set the run Trigger boolean
  public static void setRunApplicationAutomation(boolean value){
   if(value == true){
    runApplicationAutomation = true;
   }else{
    runApplicationAutomation = false; 
   }
  }
}


Trigger:

trigger applicationAutomationOnOpportunity on Opportunity bulk (before update) {

boolean runTrigger = flowControl.runApplicationAutomation();
if(runTrigger == true){

Do trigger logic

//Once complete set flow control to stop trigger from executing again.
flowControl.setRunApplicationAutomation(false);
}

}

 



Message Edited by TehNrd on 07-25-2008 08:33 PM
MDXHikerMDXHiker
Works great thanks