Skip to main content
Ilya Potapov (Krapka) 님이 #Apex에 질문했습니다
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개
  1. 2022년 2월 15일 오전 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