You need to sign in to do that
Don't have an account?

Bulkify trigger with trigger handler
I need to bulkify a trigger which utilizes a trigger handler, and am not sure how to actually call the trigger handler while using a if statement, I only need to call the trigger handler on the records that meet a specific criteria but do not know how to do it with out a for loop and calling the trigger handler multiple times. Can someone give help me out? My code is below.
for(task t: trigger.new){
system.debug('after trigger fired');
if(t.status == 'Completed' && t.Primary_Campaign__c != Null && t.Primary_Campaign__r.Actionable__c == true){
taskTriggerHandler.updateActionableLeads(Trigger.new);
}
if(t.Follow_Up_Id__c != Null){
taskTriggerHandler.followUPTaskUpdate(Trigger.new);
}
}
for(task t: trigger.new){
system.debug('after trigger fired');
if(t.status == 'Completed' && t.Primary_Campaign__c != Null && t.Primary_Campaign__r.Actionable__c == true){
taskTriggerHandler.updateActionableLeads(Trigger.new);
}
if(t.Follow_Up_Id__c != Null){
taskTriggerHandler.followUPTaskUpdate(Trigger.new);
}
}
Create a List of Tasks: In your case two: a) One for updateActionableLeads method b) followUPTaskUpdate
- Load the task into the list of tasks instead of calling the handlers until the loop has finished runnning.
- when the for loop has completed then call the trigger handler using the List of tasks as parameters instead of Trigger.New
I thinkthat should help.This is one method of bulkification - use collections like Lists, Sets, and even Maps.