Another Salesforce blog!!!

Salesforce, Apex

restrict any Trigger to fire only once

how we can avoid repeated or multiple execution of Trigger?

Triggers can fire twice, once before workflows and once after workflows, this is documented at Content/ apex_triggers_order_of_execution.htm:

“The before and after triggers fire one more time only if something needs to be updated. If the fields have already been set to a value, the triggers are not fired again.”


Add a static boolean variable to a class, and check its value within the affected triggers.

public class HelperClass {
   public static boolean firstRun = true;

trigger affectedTrigger on Account (before delete, after delete, after undelete) {
                Trigger.old[0].addError('Before Account Delete Error');

Leave a Reply

Your email address will not be published. Required fields are marked *