Tuesday, December 20, 2022

Trigger Framework in Salesforce

Learn how to completely and cleanly control your Apex code with Trigger Frameworks, why they’re useful, and the various ways to implement them. In this session will talk about Apex Trigger Framework in Salesforce and benefit of using a trigger framework. How many trigger framework are available in Salesforce, which one is lightweight apex trigger framework and Comparison of different approaches.

In this 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

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.

  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
Trigger Handler Pattern

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

Trigger Framework using a Virtual Class

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.

Trigger Framework using an Interface

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.

An architecture framework to handle triggers

Accomplishments with this Trigger framework :-

  1. One line trigger
  2. All routing is handled for us
  3. Establish all methods while letting us pick and choose which ones we want
  4. Individual event handler methods

Recording

Agenda:

  1. How Triggers Work
  2. Why Trigger Handlers
  3. Why Trigger Frameworks
  4. Create a Trigger Framework using a Virtual Class
  5. Create a Trigger Framework using an Interface
  6. Comparison of different approaches
  7. Drawbacks to Frameworks
  8. 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.

Triggers

No comments:

Post a Comment

Understanding Wire vs Imperative Apex Method Calls in Salesforce Lightning Web Components (LWC)

Understanding Wire vs Imperative Apex Method Calls in Salesforce Lightning Web Components (LWC) Introduction: Salesforce Lightning Web ...