Development questions
How do you implement a Trigger Bypass mechanism using Custom Metadata Types or Hierarchy Custom Settings?
Create a config record with a checkbox such as Bypass_Account_Trigger__c, and check it at the start of the trigger/handler.
- Hierarchy Custom Setting: value can be set per org, profile or user (e.g. bypass for the integration user or during data loads), editable without deployment, and
getInstance()doesn't use SOQL. - Custom Metadata Type: deployable with metadata, good for permanent switches, but not changeable via DML in the same transaction.
- Custom Permission:
FeatureManagement.checkPermission()for per-user bypass.
apex
Trigger_Settings__c s = Trigger_Settings__c.getInstance();
if (s.Bypass_Account_Trigger__c) return;
Also provide a static in-code bypass for tests and for avoiding recursion.
apex-triggertriggerbypasscustom-metadata
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?