In this blog post let’s learn how to use custom metadata in salesforce flow with an example.
Table of Contents
What is Custom Meta Data Types
Meta Data is data that describes the other data. So what are custom metadata types? – A custom metadata type is an object that is used to define the structure for application metadata. Example – Custom metadata is a kind of custom object, it supports field creation and we can also create a record on top of it.
Rather than storing fixed data in code [hard code], custom metadata types empower you to configure applications by constructing reusable functionality that dictates behavior based on metadata. Much of this customization work can be accomplished using declarative tools.
Custom MetaData Type In flow and Fields Support
When you create a custom metadata type in Salesforce it creates standard fields in it. Those are as below.
Apart from that, custom metadata supports custom field creation for the below data types.
Also Read: Schedule Triggered Flow in Salesforce
- Metadata Relationship
- Text Area
- Text Area (Long)
Practical Uses for Custom Metadata Types in Salesforce
If you want to use a custom metadata type in Apex, you can write an SOQL to read the custom metadata type.
To identify custom meta data the API name of the object always ends with __mdt.
For more on how to use custom metadata in Apex: Read Here.
Also, custom metadata types can be used in Apex, Flows, Formula Fields, and Validation rules.
Custom metadata types offer customizable, deployable, packageable, and upgradeable application metadata. In various scenarios, custom metadata types outperform custom settings and custom objects, providing a streamlined approach to application lifecycle management and compliance
Custom MetaData Types in Salesforce
When the account is created based on the Billing country show the ISO Code. This scenario is used for CountryAndISO mapping in Salesforce.
Step 1: Create Custom MetaData
To create a custom metadata go to setup -> search ” Custom Medata Types” then click New Custom MetaData Types. Then add the Label and API name (Object Name).
As per our use case, I’m creating a custom metadata named as,
Label: Country ISO Code Mapping
Object Name: Country_ISO_Code_Mapping
Step 2: Create Custom Fields
As per the use case I’m creating two fields one is the country standard name field which type of text and one is the ISO Code which is the type of text. Which will look like as below.
Step 3: Create custom metadata records
To create custom metadata records click Manage Country ISO Code Mappings, then click New and create records.
Step 3: Create a flow
Go to->flows and create record triggered flow. This flow will run when the record is created. In the custom account object, I have the field called ISO Code.
To update the same object we need to use Fast Field Updates. Our initial flow configuration looks like below.
Step 4: Get a Custom MetaData record in flow
To query custom metadata records in flow you need to query custom metadata type objects. So here when the account record is created I’m querying a metadata-type record based on the account billing country. Which can be done as below. [Query matching billing country from custom metadata type records].
Step 5: Null Check
As we used a null get records element in step 4, so we need to always have a null check, which can be done as below.
Also Read: How to use screen flow in Salesforce
Step 6: Update the ISO Code in the Account
After checking a null, if the get record element is not null, then we are updating the triggered record record.
So to set the value in the account record we are using the field “ISO Code” and the value is from the GET record element, which we got from Step 4.
Now we are done with our flow, let’s see the final look of the flow.
In conclusion, the combination of Custom Metadata Types and Salesforce Flow provides a robust solution for creating dynamic configurations that adapt to the evolving needs of your business. By reading this post you will understand how to use custom metadata type in salesforce flow.
If you liked our blog post, feel free to share it with your friends. Also, follow our other blog post on Salesforce.