Flow / Developers

Using Custom Metadata to Build Dynamic, Scalable Flows in Salesforce

By Kimberly Small

Salesforce Flow is a powerful, declarative development tool that allows admins and developers to create custom automations and interactive user experiences. Flow’s ability to accomplish so much without code has been a game-changer for many companies. 

Flows should be both maintainable and scalable so that they can grow right along with the business processes they are automating, but hard-coded values in flows can cause a number of issues. Let’s take a closer look at this problem, and how leveraging custom metadata types can help save the day.  

The Problem With Hard-Coded Values in Flows

Salesforce’s definition of hard-coding is:

“The software development practice of embedding output or configuration data directly into the source code of a program.”

In our case, hard-coding refers to placing values (such as IDs, business rules, etc.) directly into flows. Here are a few examples of values that I’ve personally seen hard-coded in flows:

  • IDs
  • Business Rules
  • Record Type Names
  • Emails
  • URLs
  • Queue Names
  • Email Template API Names
  • Profile / Role Names
  • Mappings

This example shows a flow with hard-coded threshold values for the Opportunity amount. These values are used to determine if an Opportunity is considered a “High-Value” deal.

Salesforce flow builder showing hard-coded Opportunity amounts in the Get Records element of a screen flow.

Many admins may not see an issue with adding these values directly in flows. In fact, they are typically quick and easy to add. However, over time, these values may need to change as business processes change. 

READ MORE: A Salesforce Professional’s Guide to Process Mapping

Every time a value change is needed, the affected flows will have to be updated directly. Which means a simple value change will require a flow deployment to production. 

This becomes an even bigger problem when these values are referenced in multiple flows. Updating a single value would mean updating multiple flows, and that’s only if you can remember or locate every flow where the value is referenced. 

This can potentially cause two main issues. First, it could cause inconsistencies and errors in each flow’s UI and automation. Also, it could cause issues with any data manipulated by these flows.

One way to combat these issues is to leverage custom metadata! 

Benefits of Using Custom Metadata

There are some benefits to using custom metadata as a flow admin. Custom metadata can be: 

  • Created, customized, and deployed by flow admins in a declarative manner.
  • Used to store values like business rules, API names, and more.
  • Used for field and value mapping.
  • Used to easily toggle flows on and off.
  • Referenced directly in flows.

So, many of the values that you typically hard-code in flows can be added to custom metadata. And once you add those values to custom metadata records, you can reference those records in your flows!

Custom Metadata Basics for Flow Admins

You can get started with Custom Metadata using a few simple steps. First, determine which values make the most sense to be stored in custom metadata records.

Value Type (often hard-coded in Flow)What to store in Custom MetadataExample
IDs (RecordTypeId, QueueId, UserId)Avoid actual IDs. Try to use DeveloperName, API Names, and other identifiers insteadRecordType.DeveloperName: “Support_Ticket”
Business RulesThresholds, flags, segments, priorities, feature toggles, etc.Minimum Amount: $25000
Maximum Amount: $100000
Record Type NamesObject API name, RecordType DeveloperNameObject API Name: “Case”, RecordType.DeveloperName: “Support_Ticket”
EmailsTo / Cc / Bcc addresses, subject / body snippetsTo address: “support@example.com”
URLsRelative paths, base URLs (avoid hard-coding full environment-specific URLs)Relative URL: /lightning/page/case_faq
Queue NamesQueue DeveloperNameQueue DeveloperName: “Billing_Queue”
Email Template API NamesTemplate API NamesEmail Template API Name: “Renewal_Reminder_Email”
Profile / Role NamesProfile / Role API NamesProfile API Name: “Sales_Manager”
MappingsSource value, target value, and contextSource Value: “VIP Customer”, Target Value = “Tier 1 Support”

Next, create a custom metadata data type with the fields needed to store important values that you don’t want to hard-code in flows. In our example, we are creating a custom metadata type to store the opportunity amount threshold values for different deal types. 

Here are some general steps that you can follow to create a custom metadata type:

  1. In Setup, navigate to Custom Metadata Types.
  2. Click on the New Custom Metadata Type button.
  3. Fill out all required fields on the Custom Metadata Type Information screen.
  4. Keep the default visibility settings (unless you are creating a managed package).
  5. Click on the Save button to save your new custom metadata type. You will be able to view the newly created custom metadata type after clicking Save.
Salesforce setup screen for a “Deal Type Configuration” custom metadata type, which shows fields and other related information.

After creating the custom metadata type, we can add a deal type field, as well as minimum and maximum amount fields to store threshold values. 

To add fields to your custom metadata type, you can follow these simple steps:

  1. Locate the Custom Fields section for your custom metadata type.
  2. Click on the New button in the Custom Fields section.
  3. Select the correct data type for the field you want to create, then click on the Next  button.
  4. Fill out all necessary fields.
  5. For Field Manageability, you’ll want to select the following option unless you want to enforce restrictions for changing field values: Any user with the Customize Application permission (managed package upgrades won’t overwrite the value).
  6. Click on the Next button.
  7. Specify if the new field should display on the page layout or not, then click on the Save button.

Next, create custom metadata records to store those values. To add new custom metadata records:

  1. Locate and click on the Manage button at the top of your custom metadata type’s page. This will open a list view for your custom metadata type’s records.
  2. Click on the New button.
  3. Fill out all necessary fields, then click on the Save button (or the Save & New button if you need to add more than 1 record).
Salesforce list view for the “Deal Type Configuration” custom metadata type, which shows metadata records with Deal Type threshold values.

And then, you can reference those custom metadata records in your flows! We will explore two different options that you can use to reference the custom metadata records in your flows.

Option 1: Query Custom Metadata Records Using Get Records

You can query the custom metadata records using a Get Records element. You will select the Custom Metadata Type you created as the object, and use specific criteria to drill down and get the metadata record(s) you need.  

In our example, we are querying the Deal Type Configuration custom metadata type, and only retrieving the “High-Value” record. 

Salesforce flow builder that shows a Get Records element that is retrieving the “High-Value” configuration record from the “Deal Type Configuration” custom metadata type.

Next, use values from the queried custom metadata records in the desired flow elements. 

In our example, we will reference the Minimum Amount and Maximum Amount fields from the queried custom metadata record in the criteria of the Get Records element that is used to retrieve Opportunity records. 

Salesforce flow builder that shows a Get Records element that is retrieving Opportunity records using the “High-Value” configuration record values from the “Deal Type Configuration” custom metadata type.

Now, when you debug test your flow, you will be able to see where the custom metadata was queried and referenced, while also verifying that everything displays as expected.

Salesforce flow debug window that shows all opportunity records that were retrieved by using the “High-Value” configuration from the “Deal Type Configuration” custom metadata type.

Option 2: Flow Formula Referencing Custom Metadata Record

If you want to avoid using additional queries in your flow, you can use flow formulas to retrieve custom metadata record field values! When creating the flow formula, you’ll want to use the pattern below:

$CustomMetadata.<Type_API_Name>.<Record_DeveloperName>.<Field_API_Name>

So, you’ll need the:

  • Custom metadata type’s API name.
  • The developer name of the custom metadata record you want to reference.
  • Field API name from the custom metadata type.

Once you create the custom metadata formulas you need, you can reference these formulas in the desired flow elements.

Salesforce flow build showing a Get Records element referencing custom metadata flow formulas that use the “Deal Type Configuration” custom metadata type.

Now, when you debug your flow, you will be able to see where the custom metadata formulas were referenced, while also verifying that everything displays as expected.

Salesforce flow debug window that shows all opportunity records that were retrieved by using the formulas for the “High-Value” configuration from the “Deal Type Configuration” custom metadata type.

Tips, Considerations, and Next Steps

Now that you understand how to use custom metadata in your flows, try the following:

  • Review existing flows that have hard-coded values, and see where custom metadata can be leveraged.
  • Keep custom metadata names clear and easy to understand.
  • Work with your team to establish standards around using custom metadata in flows.

Keep in mind that:

  • Custom metadata records are still metadata – therefore, moving these records from environment to environment typically requires a deployment rather than a data load.
  • You may want to avoid storing values that will need to change frequently. 
  • These records will typically be updated in Setup, but you can work with a developer to leverage the Metadata API for additional options.

Summary

Now you see how custom metadata can help make your flows more configurable and easier to maintain. Instead of hard-coding values in multiple flows, you can define them once in custom metadata, then reference those metadata records in each flow.

Are you currently leveraging custom metadata to make your flows more dynamic? If not, do you have plans to replace hard-coded values with custom metadata in the future? Let us know in the comments. 

The Author

Kimberly Small

Kimberly is a 8x Salesforce certified developer and founder of SkillShockTech.

Leave a Reply

Comments:

    BVSK
    March 17, 2026 3:13 am
    I think you missed to mention about permission to read custom metadata if the flow runs in user mode.