Activity › Forums › Salesforce® Discussions › What are the benefits of the “One Trigger per Object” design pattern?
Tagged: Design Pattern, Salesforce Batch Apex, Salesforce Trigger, Salesforce Visualforce Page, Test Class
-
What are the benefits of the “One Trigger per Object” design pattern?
Posted by shafali on April 28, 2016 at 7:16 AMWhat are the benefits of the “One Trigger per Object” design pattern?
Shubham replied 10 years ago 3 Members · 2 Replies -
2 Replies
-
These are some basic benefits using ‘One trigger per Object’ design pattren
- Reusability – with your logic in a class, you can now re-use it outside of triggers, for example in a Visualforce page, test class, batch Apex, etc. No need to copy code!
- Simplicity – every “trigger” gets reduced to just two lines of code in the master trigger. An object oriented code base is more organized, predictable, and modular too!
- Control your order of execution – in Apex, “the order of execution isn’t guaranteed for multiple triggers on the same object.” This pattern gives you total order control.
- Code in style! – You’re going to look like an Apex master using this pattern whether or not you take advantage of any of the benefits above. Plus, it’s a common interview question!
-
Log in to reply.