In this session we talk about all below Trigger Framework
- Trigger Handler Pattern
- Trigger Framework using a Virtual Class
- Trigger Framework using an Interface
- An architecture framework to handle triggers
Why Trigger Framework
Triggers are a powerful tool that can do great things when used correctly but cause a lot of headache when used incorrectly. Triggers without structure can be messy. They can interfere with one another and cause huge performance and debugging problems.
- Generic code that can be extended for any object
- Ensures triggers are consistently handled and only required code is needed.
- Allows for simple Triggers and handlers.
- handles routing for you
- enforce consistent trigger behavior
- Easily allows for trigger bypasses
- Allow you to enforce different behavior for triggers that start a process vs. mid process.
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.
- Apex Class that handles trigger logic
- Allows code to be called from other code or tests
- Uses specific Trigger contexts and Trigger variables for routing
- Keep Triggers Simple
- Allow for greater flexibility
- Make code reusable
- Unit tests are much easier
What is missing in Handler pattern ?
- Still duplicated code in every trigger
- How can we simplify things?
- 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. This trigger framework bundles a single TriggerHandler base class that you can inherit from in all of your trigger handlers. The base class includes context-specific methods that are automatically called when a trigger is executed
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.
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.
Accomplishments with this Trigger framework :-
- One 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
Recording
Agenda:
- How Triggers Work
- Why Trigger Handlers
- Why Trigger Frameworks
- Create a Trigger Framework using a Virtual Class
- Create a Trigger Framework using an Interface
- Comparison of different approaches
- Drawbacks to Frameworks
- Summary and Wrap Up
Trigger Actions Framework
Administrators use platform products like Flow to deliver powerful business processes, and developers can write Apex to handle more complicated scenarios. The biggest question for Salesforce architects has been how to arrange these tools together to build complete solutions. Check this post to learn about Trigger Action framework in Salesforce.
No comments:
Post a Comment