-
Lets choose beforeInsert and afterInsert methods of AccountTriggerHandler as the targets of test. Also, override the beforeInsert by adding a debug statement:
public class AccountTriggerHandler extends TriggerHandler {
...
public override void beforeInsert() {
super.beforeInsert();
System.debug('Overriden beforeInsert method executed!');
}
}
- Next, add some handlers:
public class AccountTriggerHandlerMethod_1 implements Callable {
public Object call(String action, Map<String, Object> args) {
List<Account> accounts = (List<Account>)args.get('newList');
System.debug('AccountTriggerHandlerMethod_1 class executed! ' + accounts.size() + ' records passed. - Should be the first method called');
return null;
}
}
public class AccountTriggerHandlerMethod_2 implements Callable {
public Object call(String action, Map<String, Object> args) {
List<Account> accounts = (List<Account>)args.get('newList');
System.debug('AccountTriggerHandlerMethod_2 class executed! ' + accounts.size() + ' records passed.');
return null;
}
}
public class AccountTriggerHandlerMethod_3 implements Callable {
public Object call(String action, Map<String, Object> args) {
List<Account> accounts = (List<Account>)args.get('newList');
System.debug('AccountTriggerHandlerMethod_3 class executed! ' + accounts.size() + ' records passed. - Should be the last method called (before all overrides)');
return null;
}
}
public class AccountTriggerHandlerMethod_4 implements Callable {
public Object call(String action, Map<String, Object> args) {
List<Account> accounts = (List<Account>)args.get('newList');
System.debug('AccountTriggerHandlerMethod_4 class executed! ' + accounts.size() + ' records passed.');
return null;
}
}
public class AccountTriggerHandlerMethod_5 implements Callable {
public Object call(String action, Map<String, Object> args) {
List<Account> accounts = (List<Account>)args.get('newList');
System.debug('AccountTriggerHandlerMethod_5 class executed! ' + accounts.size() + ' records passed.');
return null;
}
}
-
To trigger the test just execute this in anonymous:
Account acc = new Account();
acc.Name = 'Test';
insert acc;