CategoryTriggers

What is a bulkified trigger?

A trigger which can handle a single or a millions of records very effectively and efficiently is known as bulkified trigger. Instead of updating an object one by one, you can pour all the objects in a list and update the list just once. This is a just an example of a bulkified trigger.

A trigger is calling a number of times in the same apex transaction. How can we restrict the execution to only once?

When the trigger is following recursion, you can restrict it by using a static variable defined in another other class. Once the trigger is called, make the value of the static variable false and keep a check over the trigger so that it is not called again.

Trigger accttrigger on account(before insert){

If(runonce){

    //body of trigger

Runonce = false;

}

}

Consider this code: Trigger Accounttrigger on Account(before update){ ListaccList = new List(); For(account a : trigger.new){ // business logic accList.add(a); } Update acclist; } Is the best practice followed, or it would it require some changes?

In a trigger, the best practice is to update the trigger.new list instead of creating a new list and updating it. Thing is trigger.new will always be updated into the system by trigger. So instead of making a second update call, why don’t we put the desired values in trigger?new and let it update automatically in the system. This way can make sure our code will never break.

Recent Posts

Recent Comments

Archives

>