Saturday, 31 August 2019

Trigger Framework Salesforce

In ApexHours we did one session on Apex Trigger Framework in Salesforce with ADAM OLSHANSKY. In that session we talk about what is a benefit of using a trigger framework, How many trigger framework are available, which one is lightweight apex trigger framework and Comparison of different approaches.

In that session we talk about all below Trigger Framework
1) Trigger Handler Pattern
2) Trigger Framework using a Virtual Class
3) Trigger Framework using an Interface
4) An architecture framework to handle triggers


Why Trigger Framework ?

 A framework may, however, greatly simplify your development efforts when your code base gets large. In a nutshell, your framework should have the following goals:-
  1. Generic code that can be extended for any object
  2. Ensures triggers are consistently handled and only required code is needed
  3. Allows for simple Triggers and Handlers
  4. Handles routing for you
  5. Enforces consistent trigger behavior
  6. Easily allows for trigger bypasses

Trigger Handler Pattern

Please check this post to learn about Handler pattern and code. Lets talk about what is the advantage of Trigger Handler Patter.
  1. Apex Class that handles trigger logic
  2. Allows code to be called from other code or tests
  3. Uses specific Trigger contexts and Trigger variables for routing
  4. Keep Triggers Simple
  5. Allow for greater flexibility
  6. Make code reusable
  7. Unit tests are much easier


Please check this recording for code walk-through. What is missing in Handler pattern ?
  1. Still duplicated code in every trigger
  2. How can we simplify things?
  3. How can we make our process repeatable?

Trigger Framework using a Virtual Class

 Please check this post to learn more about Virtual Class Trigger Framework.



Please check this recording for code walk-through. Accomplishments with this Trigger framework :-
  •  1 line trigger
  • Only need to add handler methods that we want to use
  • All routing is handled for us



Trigger Framework using an Interface

 Please check this post to learn about this framework.

 Please check this recording for code walk-through. Accomplishments with this Trigger framework :-

  • 1 line trigger
  • All routing is handled for us
  • All handlers are consistent and will have the same methods
  • Multiple ways to deactivate a trigger

An architecture framework to handle triggers

 Please check this post to learn about this framework.



Please check this recording for code walk-through. Accomplishments with this Trigger framework :-
  • 1 line trigger
  • All routing is handled for us
  • Establish all methods while letting us pick and choose which ones we want
  • Individual event handler methods

Please check our YouTube Recording to learn more about all Trigger Framework and Code.
https://www.youtube.com/watch?v=U5ZOA9EY3Kg&t=7s





Here is link for all frameworks:-

Thank

No comments:

Post a Comment