Skip to main content
Hello everyone. I order to make trigger that run only once, I have a singleton like this:

public class SingletonTriggerHelper {

    private static Boolean flag = true;

    public static void OnAfterInsert (List <Account> accounts) {

        if (flag) {

        for (Account account:accounts){

            account.Name =  account.Name +' '+ string.valueof(Datetime.now());

        }

        flag = false;

        }

    }

}

The question is about correct usage of it. Do I have to instantiate  SingletonTriggerHelper?  Where do I have to call OnAfterInsert? I will be gratefull for any help.
1 resposta
  1. 15 de fev. de 2022, 10:50
    Hi ,

    It would be better to prevent the recursion in the trigger it self if the entire method need not call for the second time .

    If you have a method and some part of it should be called only once then you may use the recursion prevention in the Handler.

    If this solution helps, Please mark it as best answer.

    Thanks,

     
0/9000