Created
March 22, 2017 00:11
-
-
Save douglascayers/d9c3ba9c00c3e3dd06189524980f74df to your computer and use it in GitHub Desktop.
Example trigger that delegates to helper class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger AccountTrigger on Account ( before insert, before update, before delete, | |
after insert, after update, after delete ) { | |
AccountTriggerHandler handler = new AccountTriggerHandler(); | |
if ( Trigger.isBefore && Trigger.isInsert ) { | |
handler.handleBeforeInsert( Trigger.new ); | |
} | |
else if ( Trigger.isBefore && Trigger.isUpdate ) { | |
handler.handleBeforeUpdate( Trigger.old, Trigger.oldMap, Trigger.new, Trigger.newMap ); | |
} | |
else if ( Trigger.isBefore && Trigger.isDelete ) { | |
handler.handleBeforeDelete( Trigger.old, Trigger.oldMap ); | |
} | |
else if ( Trigger.isAfter && Trigger.isInsert ) { | |
handler.handleAfterInsert( Trigger.new, Trigger.newMap ); | |
} | |
else if ( Trigger.isAfter && Trigger.isUpdate ) { | |
handler.handleAfterUpdate( Trigger.old, Trigger.oldMap, Trigger.new, Trigger.newMap ); | |
} | |
else if ( Trigger.isAfter && Trigger.isDelete ) { | |
handler.handleAfterDelete( Trigger.old, Trigger.oldMap ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class AccountTriggerHandler { | |
public AccountTriggerHandler() {} | |
// ------------------------------------------------------- | |
// INSERT | |
// ------------------------------------------------------- | |
public void handleBeforeInsert( List<Account> newList ) { | |
// no logic yet | |
} | |
public void handleAfterInsert( List<Account> newList, Map<ID, Account> newMap ) { | |
// no logic yet | |
} | |
// ------------------------------------------------------- | |
// UPDATE | |
// ------------------------------------------------------- | |
public void handleBeforeUpdate( List<Account> oldList, Map<ID, Account> oldMap, | |
List<Account> newList, Map<ID, Account> newMap ) { | |
// no logic yet | |
} | |
public void handleAfterUpdate( List<Account> oldList, Map<ID, Account> oldMap, | |
List<Account> newList, Map<ID, Account> newMap ) { | |
// no logic yet | |
} | |
// ------------------------------------------------------- | |
// DELETE | |
// ------------------------------------------------------- | |
public void handleBeforeDelete( List<Account> oldList, Map<ID, Account> oldMap ) { | |
// no logic yet | |
} | |
public void handleAfterDelete( List<Account> oldList, Map<ID, Account> oldMap ) { | |
// no logic yet | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment