Dynamic Control of Automations on Salesforce (chapter 2 of 3)

Custom Metadata Types 

A custom metadata type serve as a blueprint for defining the structure of application metadata. It comprises fields and their values that are purely “metadata oriented. The entries within custom metadata types represent metadata rather than actual data. Leveraging metadata offers flexibility as it permits importing into Salesforce, editing via the interface, and manipulation through the Metadata API. By utilizing custom metadata types, you can establish configurable applications by creating reusable functions that dictate behavior based on metadata. This approach allows for extensive customization using declarative tools You could check more theoretical details about “Custom Metadata Types” on our recent post about here: https://folderit.net/salesforce-custom-metadata-types.

  1. Create a custom metadata type and add appropriate fields.
    [Figure 1: Custom Metadata creation screen]

For this case we create three Fiels: isActive__c for control whole object automation active/deactivate, and bypassAfter__c/bypassBefore__c specific for trigger control object control. So, if isActive__c whole automation over current object should be bypassed, that automation could be a trigger but also could be a validation rule or another. In case we are working on trigger automation case, we have two option more for give as more flexibility bypassAfter__c/bypassBefore__c. So, if isActive__c = false, next step on apex will be check after/before status, bypassBefore__c = true all automation related to this context will be skipped, similar situation for bypassAfter__c. 

2. Create the custom metadata type record.
We will create two records, one for a global skip execution and another for a specific object “Contact”.

[Figure 2: custom metadata types of records]
For the example was decided to skip all things related to before trigger on “Contact”.

[Figure 3: Contact records configuration]

3. How to use these configuration – Add the custom metadata type control reference to your automations in Flow, Apex, Validation Rule, etc. Examples of use.


  • For Apex triggers 
[Figure 4: Trigger use code example]
[Figure 5: Handler class used for the example]
  • For Flow 

Create a new Flow, for when a “Contact” object is updated. 

[Figure 6: Type of flow you need select]
To reference your custom metadata type in Flow, first use the Get Records element to retrieve the control information.

[Figure 7: Flow creation screen]
Then, add a decision element to check   : for this case our MDT records are configured as a default “False” and when it is false we should not be bypassing the automation. 

[Figure 8: conditional step]
  • For Validation Rules 

Create a validation rule on “Contact” object.

[Figure 9: validation rule]
For this case our configuration on custom metadata type records is next: global and contact bypass are not active, so validation should be executed. 

[Figure 10: MDT configuration for validation]
If for some reason it is required skip validation for “Contact”, you can modify the registry value as follows. “bypassAfter”/”bypassBefore” are irrelevant here, it’s just used for the trigger case. 

[Figure 11: MDT configuration for validation]

Cons of Using Custom Metadata Types: 

End-User Accessibility: Custom metadata types are typically managed by administrators or developers with elevated permissions, limiting easy access for end users. 

Non-Hierarchical Structure: Lack of hierarchical organization in custom metadata type records may require complex logic for execution control based on user context. 

Dependency Concerns: Automations relying on specific custom metadata type records may face disruptions if these records are deleted, potentially causing breaks in the automation flow. 

Pros of Using Custom Metadata Types: 

Testability and Deployment: Custom metadata type records are metadata, enabling easy referencing in unit tests and access via the Metadata API. They are automatically copied to all sandboxes and can be tracked in version control systems. 

Salesforce Support: Salesforce is dedicated to improving and supporting custom metadata types. 

Customizability: Building custom fields and relationships for custom metadata types offers a highly adaptable solution. 

Programmatic Access: Apex methods can be utilized to retrieve custom metadata types. 

Next Chapter “Custom Settings”: Dynamic Control of Automations on Salesforce (chapter 3 of 3)

Previous Chapter “Custom Permissions”: Dynamic Control of Automations on Salesforce(chaper 1 of 3)

Note: You could check all the metadata and code I used for this example on this repository on github: cristiaan30033/Salesforce-Dynamic-Control-of-Automations: Examples how to implements controls for triggers, validations rules, etc. on salesforce platform (github.com) 

Why you should augment your team with Folder IT

Outsourcing or Augmenting your Salesforce Team with Folder IT professionals is a cost effective solution that does not sacrifice on quality nor communication effectiveness. Our teams are qualified for working with all the latest technologies and for joining you right away.

Request a quote now for outsourcing your project or staff augmentation services to Argentina.


Access top talent now!


Get in Touch