Because the methods in the TriggerHandler
class are ultimately invoked during an Apex trigger context, they have access to the trigger context variables such as Trigger.new
and Trigger.old
. Additionally, if the context supports it, you'll have access to Trigger.newMap
and Trigger.oldMap
. While you have access to these collections in the TriggerHandler
class, you must cast them to typed collections. This is required because Apex actually returns a collection of generic sObjects rather than collections of sObject subclasses, such as Account
, Opportunity
and so on. With this in mind, it's a good idea to use the constructor of your trigger handler to set a few class level variables that are precast to the object your handler works with, as follows:
public class AccountTriggerHandler extends triggerHandler { List<Account> triggerOld; Map<id, Account> triggerNewMap; Map<id, Account> triggerOldMap; public AccountTriggerHandler(){ this.triggerNew...