6.1 Framework, why?

In Chapter 3 and 4 we have introduced how to write a trigger. And in Lecture 4.2 we have introduced TriggerHandler class.

In most Salesforce orgs and implementations, I would highly suggest you using a TriggerHandler framework. I hear what you say, why bother? Isn’t the TriggerHandler class we have introduced in 4.2 good enough?

Well, for tiny projects, it might be good enough. But for any enterprise structure, even though we can still use it, it is much better to apply a TriggerHandler framework. That’s because for most triggers, we have a bunch of similar requirements:

  1. We need to run the different functions in a chronicle order: before insert, before update, after insert, after update, before delete.
  2. We need to get rid of infinite loops.
  3. We need to provide a way to reset the infinite loop counter. So in case of update contact1; update contact2; We can ensure the trigger runs for both SObjects.
  4. We need to provide a method to overpass the trigger running so that some legacy data can still be pushed through.
  5. And other things (like logging, limit tracking, etc.). You can also add them into your TriggerHandler class.

For all those reasons, it is highly recommended here that we should have a base TriggerHandler class and let all the TriggerHandlerSObject classes inherit from that base class.

And that, is our TriggerHandler framework.

Remember, the TriggerHandler class is here to help us make things easier, not making it harder. And it is not hard to apply it.

Next Post

6.2 Introducing Kevin O’hara’s Trigger handler framework

Subscribe to Sfdcinpractice

Subscribe to get the latest blogs and tutorials of sfdcinpractice. No spam, no trash, only the awesome posts from sfdcinpractice. 

Leave a Reply

Your email address will not be published / Required fields are marked *