Salesforce Trigger Framework driven by Custom Metadata
This custom Salesforce trigger framework is designed to provide a highly configurable and easy-to-manage solution for handling Salesforce triggers. It is driven by custom metadata, which allows for a high degree of customization and flexibility.
The framework is built around the concept of "features", which are essentially individual pieces of functionality that can be executed in response to a trigger event. Each feature is represented by an implementation of the ITriggerExecutable
interface, which defines a single execute
method that takes a TriggerContext
object as an argument.
The TriggerContext
object encapsulates the state of the trigger at the time of execution, including the operation type (insert, update, delete, etc.), the old and new values of the records, and other relevant information. This allows the feature to make decisions based on the current state of the trigger.
The TriggerFeature__mdt
custom metadata type has several fields that control the behaviour of the features:
Asynchronous__c
: If this field is set to true, the feature will be executed asynchronously using theSystem.enqueueJob
method. This can be useful for long-running operations, but it should be used with caution, as there are limits to the number of asynchronous jobs that can be executed.LoadOrder__c
: This field determines the order in which the features are executed. Features with a lower load order are executed before features with a higher load order.UsernamesToExclude__c
: This field allows you to specify a semicolon-separated list of usernames for which the feature should not be executed. This can be useful for excluding certain users from the effects of the feature.
In summary, this custom Salesforce trigger framework provides a flexible and configurable way to handle triggers, with the ability to control the execution order, exclude certain users, and run features asynchronously. However, the Asynchronous__c
feature should be used with caution due to Salesforce's limits on asynchronous jobs.
The source code for this framework is available on GitHub at https://github.com/vncasolns/salesforce-trigger-framework.
0 Comments:
Post a Comment