Created
December 16, 2016 09:17
-
-
Save swapnilshrikhande/a6ac0f83fb756cdda85c9a48ceb4ff48 to your computer and use it in GitHub Desktop.
AccountTrigger Template
This file contains hidden or 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 abstract class AccountTrigger { | |
public Account[] accountOldList { set; get; } | |
public Account[] accountNewList { set; get; } | |
public Map<Id, Account> accountOldListMap = new Map<Id, Account>(); | |
public Map<Id, Account> accountNewListMap = new Map<Id, Account>(); | |
public AccountTrigger(Account[] accountOldList, Account[] accountNewList) { | |
this.accountOldList = accountOldList == null ? new Account[] {} : accountOldList; | |
this.accountNewList = accountNewList == null ? new Account[] {} : accountNewList; | |
initializeMap(this.accountOldList, accountOldListMap); | |
initializeMap(this.accountNewList, accountNewListMap); | |
} | |
public void initializeMap(Account[] accountList, Map<Id, Account> accountListMap) { | |
for(Account account : accountList) { | |
if(contact.Id != null) { | |
accountListMap.put(account.Id, account); | |
} | |
} | |
} | |
public abstract Boolean executable(Account accountOld, Account accountNew); | |
public virtual void execute() { | |
Account[] accountUpdateableList = new Account[] {}; | |
for(Account accountNew : accountNewList) { | |
Account accountOld = accountOldListMap.get(accountNew.Id); | |
accountOld = accountOld == null ? new Account() : accountOld; | |
if( executable(accountOld, accountNew) ) { | |
accountUpdateableList.add(accountNew); | |
} | |
} | |
if( !accountUpdateableList.isEmpty() ) { | |
execute(accountUpdateableList, trigger.IsAfter == true); | |
} | |
} | |
public virtual void execute(Account[] accountList, Boolean forceUpdate) { | |
} | |
public Boolean getIsDifferent(Account accountOld, Account accountNew, Schema.SObjectField sobjectField) { | |
return accountOld.get(sobjectField) != accountNew.get(sobjectField); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment