Use Custom Metadata Types in Flows
Learning Objectives
- Explain how to reference a custom metadata type record in a flow.
- Use Flow Builder to reference a custom metadata type and include its record information in flow.
Overview
Good progress so far! Let’s keep the momentum going, because we can do even more with custom metadata types.
Before we continue, though, make sure that you’ve checked out how to use Salesforce Flow tools in Trailhead. We’re going to reference a custom metadata type record in a flow. Still learning the ins and outs of using Flow Builder? Our example here is super simple, so don’t fear. When you see how you can use custom metadata types in Flow Builder, you’ll want to build your own flow.
You probably already know that Flow Builder is a tool that you can use to automate business processes. Acme Services is a large, multinational service company, so creating repeatable business flows is crucial to functioning efficiently.
Acme Services wants to automatically update the support tier associated with an account when the account reaches a required spending threshold. Because Acme Services imports a lot of data from external systems, they need to automate this process using flows that run on a schedule.
Create a Flow That References a Custom Metadata Type Record
In the Create and Manage Custom Metadata Types unit, you created a custom metadata type called Support Tier. This unit references that custom metadata type and record for a flow.
Let’s create our flow:
- From Setup, enter Flows in the Quick Find box, then select Flows.
- Click New Flow, select Screen Flow, and click Create.
- Click
, and then select Get Records.
- For the label, enter
Get Support Tier Config
.
We need to reference the Support Tier records to help us update accounts where minimum spending has reached Gold status. - The API Name is automatically set to Get_Support_Tier_Config.
- For Object, select Support Tier.
- For Filter Support Tier Records, select All Conditions Are Met (AND) and enter these values.
Field Operator Value MasterLabel Equals Gold - Set the Sort Order to Ascending and Sort By to DeveloperName.
- Click Done. You’ve successfully identified the Support Tier object, filtered the object’s records, and set the sort for the filtered records. Next, you’ll update those records.
Update the Account Records
In an Update Records element, you identify which records to update and how you want to update those records. Based on the configuration records that we got, we want to update some accounts.
- Click
below the Get Records element, and then select Update Records.
- For Label, enter
Update Gold Accounts
. - The API Name is automatically set to Update_Gold_Accounts.
- Click Specify conditions to identify records, and set fields individually.
- For Object, select Account.
- For Filter Account Records, select All Conditions Are Met (AND) and enter these values.
Field Operator Value Total_Spending__c Greater Than or Equal {!Get_Support_Tier_Config.Minimum_Spending__c} - In the Set Field Values for the Account Records section, add the field values.
Field Value Support_Tier__c Gold - Click Done.
Connect the Flow
Save and activate the flow.
- Click Save.
- Enter a Flow Label and Flow API Name.
- Click Save.
- Click Activate.
Any previously activated version (if one exists) is deactivated.
Check the Flow
We want to make sure that the flow will update the records, so before running the flow, let's confirm the current Support Tier value and change the opportunity amount.
- From the App Launcher (
), select Sales and click on the Accounts tab.
- Open the Beebs Publishing account and click the Details tab.
- Confirm that the Support Tier is Bronze.
- Click the Related tab
- From Beebs Publishing Q1 opportunity, select Edit.
- Change Amount to
5,500
and click Save. - Go back to the Flow Builder window and click Run.
- Open the Beebs Publishing account and refresh the page.
The Support Tier should now be Gold.
The account records with a minimum value that meets or exceeds the minimum in the Gold Support Tier record are updated to the Gold tier. And that’s it. You just created a flow that references custom metadata type records.
- We created a custom metadata type and added records to it.
- We referenced a custom metadata type record in a formula and also in a default value.
- We created a validation rule based on a custom metadata type record.
- We used records from a custom metadata type in a flow.
If you continue to the next module, and we hope you do, you can learn about some of the more technical aspects of working with custom metadata types.