Skip to main content

Trigger Framework

Seven20 includes a framework that facilitates the easy creation of trigger actions, management of said actions, and integrating them with existing Seven20 trigger actions. This is achieved through a table-driven approach, which enables the individual actions performed on a trigger invocation to be finely controlled and managed, allowing for predictable and consistent triggers, regardless of whether custom code is involved.

What is a table-driven trigger framework?

A trigger framework is a structured approach to developing and managing Apex triggers in a Salesforce application. It provides a set of guidelines and patterns to organise and execute trigger logic efficiently and consistently. The Seven20 framework takes this a step further, by utilising a table, in our case a custom metadata type, to control the behaviour of apex triggers. This framework provides us many benefits, such as:

Structured and consistent execution

The table-driven trigger framework ensures that trigger actions are executed in a structured and consistent manner. By using a custom metadata type as a table to store configuration data, developers can easily manage and modify the trigger's behavior without altering the underlying code. This helps maintain a predictable, well-organised, and self documenting trigger execution flow.

Centralised control

With the table-driven approach, all trigger actions and their configurations are stored in a centralised location. This centralised control simplifies the process of making changes to trigger behavior without deploying new code, making it more flexible and agile.

Reduced code complexity

By offloading the control of trigger actions to custom metadata, the trigger code itself can remain relatively simple and focused on handling the core logic. This separation of concerns leads to cleaner and more maintainable code.

Scalability and extensibility

As needs and requirements grow and evolve, the trigger framework can easily scale to accommodate new trigger actions or modifications. New actions are easy to add and existing actions can be easily managed without the need to modify code.

Fine grained control

Each individual trigger action can be finely controlled through the custom metadata type, allowing you to enable or disable actions as needed, or tweak the invocation order as required.

Integration with Seven20 code

The Seven20 trigger framework makes it seamless to integrate new trigger actions with packaged ones, ensuring custom code and packaged code can work together in harmony.

Code toggle switches

The trigger framework provides mechanisms for enabling and disabling code, either on mass, or specific trigger actions, without the need to deploy new code. This provides benefits such as being able to easily turn off code if dangerous bugs are discovered, or to disable triggers during a data migration - all without having to deploy any code.

Versioning and auditing

Because the trigger actions and configurations are stored as records in a custom metadata type, they can be integrated into source control so changes can be tracked over time.

warning

The trigger framework does not have functionality for recursion prevention. If your triggers are causing recursion, re-evaluation of your trigger logic is required, as it suggests a design flaw.