You need to sign in to do that
Don't have an account?
Simon234
How to make more methods in Trigger Helper class?
How can I make more methods in this Helper class, not just public static void?
I also need a method for checking the update of Stage__c field (when we update another fields - Trigger shouldn't be started).
Helper:
I also need a method for checking the update of Stage__c field (when we update another fields - Trigger shouldn't be started).
Helper:
public with sharing class JobTriggerHelper { public static void create(List<Job__c> jobList){ List<Task> taskList = new List<Task>(); for(Job__c job : jobList){ if(job.Stage__c == 'Closed'){ Task t = new Task( Subject = 'Closed', taskList.add(t); } try{ insert taskList; } catch(DMLException e){ jobApp.addError('Error message'); } } } }Trigger:
trigger JobTrigger on Job__c (after insert, after update) { if(Trigger.isAfter){ if(Trigger.isInsert || Trigger.isUpdate){ JobTriggerHelper.create(Trigger.new); } } }
1) http://amitsalesforce.blogspot.com/2015/06/trigger-best-practices-sample-trigger.html
You can try like below
public with sharing class JobTriggerHelper {
public static void create(List<Job__c> jobList){
List<Task> taskList = new List<Task>();
for(Job__c job : jobList){
if(job.Stage__c == 'Closed'){
Task t = new Task(
Subject = 'Closed',
taskList.add(t);
}
try{
insert taskList;
} catch(DMLException e){
jobApp.addError('Error message');
}
}
}
public void updateStage(List<Job__c> jobList)
{
add your logic here
}
}
Call the same method in Trigger like below
trigger JobTrigger on Job__c (after insert, after update) {
JobTriggerHelper helper = new JobTriggerHelper();
if(Trigger.isAfter){
if(Trigger.isInsert || Trigger.isUpdate){
JobTriggerHelper.create(Trigger.new);
helper.updateStage(Trigger.new);
}
}
}
Let us know if this will help you