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
imAkashGargimAkashGarg 

Make a trigger run only once

A trigger can be fired twice, if there is a workflow too on the same object updating the field.

Is there a way, we can restrict the trigger to fire only once?

sai.sfsai.sf

if you want to block recursing you can declare a static variable in a Apex class and check the value of the variable before doing any dml.

public class Recursion blocker{
   public static Boolean flag = true;
}

trigger updateaccountstatus on Opportunity (after update){
   if(RecursionBlock.Flag = true){
           RecursionBlock.Flag = false;
          //do your operation here
    }
}