can you append two active record relations code example
Example 1: can we write multiple trigger on an object salesforce
public class TestObjectTriggerHelper{
public TestObjectTriggerHelper(){
// constructor logic
}
public void beforeInsert(List<TestObject__c> newLst, List<TestObject__c> oldLst){
// before insert action code block
// method_1(); By calling different methods in other classes, you can change the order of execution also
// method_2();
}
public void beforeUpdate(List<TestObject__c> newLst, List<TestObject__c> oldLst){
// before update action code block
// method_1();
// method_2();
}
........
...
public void afterInsert(List<TestObject__c> newLst, List<TestObject__c> oldLst){
// after insert action code block
// method_1();
// method_2();
}
public void afterUpdate(List<TestObject__c> newLst, List<TestObject__c> oldLst){
// after update action code block
// method_1();
// method_2();
}
........
....
}
Example 2: can we write multiple trigger on an object salesforce
trigger TestObjectTrigger on TestObject__c (before insert, after insert, before update, after update,...) {
TestObjectTriggerHelper helper = new TestObjectTriggerHelper();
if(trigger.isBefore) {
if(trigger.isInsert) {
helper.beforeInsert(trigger.new, trigger.old);
}
if(trigger.isUpdate) {
helper.beforeUpdate(trigger.new, trigger.old);
}
....
..
.
}
if(trigger.isAfter) {
if(trigger.isInsert) {
helper.afterInsert(trigger.new, trigger.old);
}
if(trigger.isUpdate) {
helper.afterUpdate(trigger.new, trigger.old);
}
....
..
.
}
}