Skip to content

Instantly share code, notes, and snippets.

@suddeb
Created August 2, 2015 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suddeb/b2cab575aa0bf96f7be7 to your computer and use it in GitHub Desktop.
Save suddeb/b2cab575aa0bf96f7be7 to your computer and use it in GitHub Desktop.
public class AccountTriggerHandler {
//After Insert Handler
public class AccountAfterInsertHandler implements MyTriggers.Handler{
public void handle(){
System.Debug(LoggingLevel.INFO,'Inside AccountAfterInsertHandler');
}
}
//Before Insert Handler
public class AccountBeforeInsertHandler implements MyTriggers.Handler{
public void handle(){
System.Debug(LoggingLevel.INFO,'Inside AccountBeforeInsertHandler');
//Hold Trigger Context Variables
List<Account> allNewAccounts = Trigger.new;
for(Account singleAccount : allNewAccounts){
if(singleAccount.Rating == 'Hot'){
singleAccount.Active__c = 'Yes';
singleAccount.CustomerPriority__c = 'Medium';
}
}
}
}
//Before Update Handler
public class AccountBeforeUpdateHandler implements MyTriggers.Handler{
public void handle(){
//Hold Trigger Context Variables
List<Account> allNewAccounts = Trigger.new;
Map<Id, SObject> oldAccountMap = Trigger.oldMap;
//Check if there is account name change
isAccountNameChanged(allNewAccounts,oldAccountMap);
}
private void isAccountNameChanged(List<Account> allNewAccounts,Map<Id, SObject> oldAccountMap){
Integer countOfAccountNameChanged = 0;
for(Account singleAccount : allNewAccounts){
Account oldAccount = (Account)oldAccountMap.get(singleAccount.Id);
if(!singleAccount.Name.equals(oldAccount.Name)){
countOfAccountNameChanged++;
}
}
System.Debug(LoggingLevel.INFO, 'Number of Account Name Changed: ' + countOfAccountNameChanged);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment