Using the framework

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 ...

Get Mastering Application Development with Force.com now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.