-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccountTriggerHandler.cls
65 lines (51 loc) · 1.86 KB
/
AccountTriggerHandler.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
public with sharing class AccountTriggerHandler {
private boolean m_isExecuting = false;
private integer BatchSize = 0;
public AccountTriggerHandler(boolean isExecuting, integer size){
m_isExecuting = isExecuting;
BatchSize = size;
}
public void OnBeforeInsert(Account[] newAccounts){
//Example usage
for(Account newAccount : newAccounts){
if(newAccount.AnnualRevenue == null){
newAccount.AnnualRevenue.addError('Missing annual revenue');
}
}
}
public void OnAfterInsert(Account[] newAccounts){
}
@future public static void OnAfterInsertAsync(Set<ID> newAccountIDs){
//Example usage
List<Account> newAccounts = [select Id, Name from Account where Id IN :newAccountIDs];
}
public void OnBeforeUpdate(Account[] oldAccounts, Account[] updatedAccounts, Map<ID, Account> accountMap){
//Example Map usage
Map<ID, Contact> contacts = new Map<ID, Contact>( [select Id, FirstName, LastName, Email from Contact where AccountId IN :accountMap.keySet()] );
}
public void OnAfterUpdate(Account[] oldAccounts, Account[] updatedAccounts, Map<ID, Account> accountMap){
}
@future public static void OnAfterUpdateAsync(Set<ID> updatedAccountIDs){
List<Account> updatedAccounts = [select Id, Name from Account where Id IN :updatedAccountIDs];
}
public void OnBeforeDelete(Account[] accountsToDelete, Map<ID, Account> accountMap){
}
public void OnAfterDelete(Account[] deletedAccounts, Map<ID, Account> accountMap){
}
@future public static void OnAfterDeleteAsync(Set<ID> deletedAccountIDs){
}
public void OnUndelete(Account[] restoredAccounts){
}
public boolean IsTriggerContext{
get{ return m_isExecuting;}
}
public boolean IsVisualforcePageContext{
get{ return !IsTriggerContext;}
}
public boolean IsWebServiceContext{
get{ return !IsTriggerContext;}
}
public boolean IsExecuteAnonymousContext{
get{ return !IsTriggerContext;}
}
}