Each feature switch is represented as a new record in the Metadata Type, which does not require changing the actual type itself as it would for Custom Settings. So, my personal preference is to work with Custom Metadata Types. In Salesforce, I would consider feature switches to typically be of a global scope only. Each feature switch would be represented as a checkbox field in the Custom Setting. The downside to this approach is that any new feature switch requires the Custom Settings metadata to change, which is not ideal. Depending on what use cases the feature switches are needed for, this might be a desirable option. This can either be done by using Custom Metadata Types or Custom Settings.Ĭustom Settings have the advantage that they allow for hierarchical overrides of the global settings. How to Implement Feature Switches For Data Loads in Salesforceįeature switches are based on a configuration object. In Salesforce, this principal can be used to quickly turn off all your trigger functionality to run data uploads – without the risk of trigger errors. This also improves the speed of your data upload.
In traditional software development, especially in cloud applications, this practice is used for controlled feature deployments, A/B testing, and more. Feature switches are a simple concept of turning features on and off. Turning Apex Triggers On and Off with Feature SwitchesĪ possible solution to this dilemma can be the implementation of feature switches. However, some unit tests may depend on other triggers or automations to be active, which can make this a very complex and time-consuming undertaking.
That is because any changes to triggers can only be done through code deployments, and those require the unit tests to succeed for the changes to take effect. This can be done directly in the Production Org, or even better, by using tools such as the Ben Edward’s Salesforce Switch.Īlthough the tool also offers to turn off triggers, it isn’t quite that simple.
These are like stored procedures, like updating any record or setting permissions, typically used to perform operations that are based on specific conditions.Īpex Triggers can do anything such as executing SOQL or DML, calling custom actions or performing actions that are impossible to do using the elementary point-and-click tools in the Salesforce user interface like using validation rules for validating record on the field or workflow rules to update any record.Dealing with larger data loads in Salesforce often leads to the task of turning off automations, such as validation rules, workflows or process builder flows. Triggers are the apex scripts that perform the custom actions such as insertions, updates, or deletions before or after the occurrence of any specific data manipulation language (DML) event on the record. Apex can be executed by triggers based on any given conditions or with a block of code executing recurrently.ĭatabase system supports triggers and apex offers triggers to manage records. Apex is, like Java for Salesforce, a strongly typed object oriented programming language enabling the developers to interact or add the data to the lightening platform with flow and transaction control statements using variables, data types, classes and if-else statements.