Skip to content

Instantly share code, notes, and snippets.

@amitastreait
Last active March 22, 2018 10:29
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 amitastreait/75b1efc655d1af7e0a9a3c1857775d6b to your computer and use it in GitHub Desktop.
Save amitastreait/75b1efc655d1af7e0a9a3c1857775d6b to your computer and use it in GitHub Desktop.
/*
@Author : Amit Singh
@BuiltDate : 21st March 2018
@Description : Handler class that will be created by developer and allowed only one for every object
*/
public class AccountTriggerHandler implements TriggerInterface{
public void BeforeInsert(List<SObject> newItems) {
/* Update the Account name before account inserted into Salesorce */
for(Account acc : (List<Account>)newItems){
acc.Name = 'Trigger FrameWork ' +acc.Name;
}
}
public void BeforeUpdate(Map<Id, SObject> newItems, Map<Id, SObject> oldItems) {}
public void BeforeDelete(List<sObject> oldRecordsList , Map<Id, SObject> oldItems) {}
public void AfterInsert(List<sObject> newRecordsList , Map<Id, SObject> newItems) {
Try{
}Catch(System.Exception ex){
/* Call the TransactionLogHandler class method to create a log
parameters need to pass in the method are System.Exception and the Handler ClassName
*/
TransactionLogHandler.doHandleException(ex , 'AccountTriggerHandler');
}
}
public void AfterUpdate(Map<Id, SObject> newItems, Map<Id, SObject> oldItems) {
/* Update the AccountNumber */
List<Account> accountToUpdateList = new List<Account>();
Try{
for(Account acc : [Select Id, Name, AccountNumber From Account Where Id =: newItems.keySet()]){
acc.AccountNumber = '123345543625253735';
accountToUpdateList.add(acc);
}
/* Update Account and Test if the Recursion is Being prevented */
update accountToUpdateList;
}Catch(System.Exception ex){
/* Call the TransactionLogHandler class method to create a log
parameters need to pass in the method are System.Exception and the Handler ClassName
*/
TransactionLogHandler.doHandleException(ex , 'AccountTriggerHandler');
}
}
public void AfterDelete(Map<Id, SObject> oldItems) {}
public void AfterUndelete(List<sObject> newRecordsList , Map<Id, sObject> newItems) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment