AUTOMATION Β· 13 min lezen

Custom Metadata Types in Salesforce

Configurable automation without hardcoded values.

When building automation in Salesforce, you quickly run into situations where you need values that apply across multiple processes – think prices, percentages, email addresses or API endpoints. You could hardcode these in your Flow or Apex, but that makes maintenance difficult. Every change requires a new deployment or Flow modification.

Custom Metadata Types (CMDT) offer a practical solution: you store configuration data as metadata instead of operational data. This means you can change values without modifying code, and your settings automatically travel between sandbox and production. In this article, we explain what Custom Metadata is, when to use it, and provide practical examples.

Definition

What is Custom Metadata?

Custom Metadata Types are metadata – not operational data like Accounts or Opportunities. That sounds abstract, but the difference is crucial: metadata describes how your system works, while data describes what happens in your system.

Advantages of Custom Metadata

  • βœ“
    Included in deployments

    Custom Metadata records automatically travel with change sets, packages and deployments – just like custom fields or page layouts.

  • βœ“
    Consistent across environments

    No manual transfer of configuration. What you build in sandbox works the same in production.

  • βœ“
    No hardcoding in Flow or Apex

    Your logic stays generic. Values live in metadata records, not in the code.

  • βœ“
    Manageable by admins

    An administrator can adjust Custom Metadata records without developer skills or deployment.

Application

When do you use Custom Metadata?

Custom Metadata is meant for configuration data or rules that rarely change but are crucial for your processes. Think rates, thresholds, endpoints, sender details or calculation parameters. Below are four fictional examples showing when Custom Metadata is genuinely valuable.

Use case 1 – Pricing logic for subscriptions

A fictional software company offers various subscriptions. Prices depend on duration and number of users. Instead of hardcoding these prices in Apex or Flow, they're stored in Custom Metadata.

NameDuration (months)UsersPrice/month
Starter_12121–5€49
Starter_24241–5€45
Business_12126–20€89

How does it work? A Flow retrieves this metadata based on duration and number of users, calculates the price and fills it in on the Opportunity. When prices change, you only adjust the metadata records – the Flow remains unchanged.

Use case 2 – Regional surcharges

A fictional courier service charges a surcharge per region on the order amount. These surcharges are stored in Custom Metadata.

RegionSurcharge (%)
Randstad8
Noord5
Zuid6

How does it work? A Flow looks at the customer's region, retrieves the correct surcharge from Custom Metadata and calculates the total amount. When surcharges change, you only adjust the metadata.

Use case 3 – Email senders per brand

A fictional organization has multiple brands, each with its own sender identity. Custom Metadata ensures flows automatically select the correct sender.

BrandSender nameEmail address
GreenTechGreenTech Teaminfo@greentech.nl
SolarNextSolarNext Supportsupport@solarnext.nl

How does it work? A Flow looks at the customer's brand, retrieves the correct sender from Custom Metadata and uses it in the email action. Adding a new brand? Just create a new metadata record.

Use case 4 – API settings per environment

A fictional integration calls an external system. The API URL and key differ per environment. With Custom Metadata, you don't need to adjust your code or Flow per environment.

EnvironmentAPI Base URLAPI Key
Testhttps://api-test.ordersystem.nltest123
Productiehttps://api.ordersystem.nllive987

How does it work? Your Apex class or Flow detects the environment (for example via a Named Credential or organization ID), retrieves the correct metadata record and uses that URL and key. Each environment has its own metadata records – no manual adjustments needed.

Difference

Why not a Custom Object?

Many people ask: why not use a Custom Object? The answer lies in the difference between operational data and configuration.

UsageChoose
Operational data (Accounts, Orders, Transactions)Custom Object
Configurable logic / configurationCustom Metadata
Temporary or user-specific dataCustom Settings

Note: Custom Metadata automatically travels with deployments. Custom Object data must be manually transferred between environments (via data import/export or API). For configuration, that's inconvenient.

Technical

Where can you use Custom Metadata?

In Flows via Get Records

Since Summer '20 you can fully query Custom Metadata with the Get Records element. You can filter on fields and use the values in your Flow logic.

In Apex

Use to retrieve all records, or query with SOQL: MyType__mdt.getAll()

List<Subscription_Price__mdt> prices = [SELECT Prijs__c FROM Subscription_Price__mdt WHERE Looptijd__c = 12];

In Validation Rules

You can use Custom Metadata to define dynamic exceptions or thresholds in validation rules.

In formulas or record types

Use metadata to determine default values or conditions without hardcoding.

Practice

Fictional practical example – Energy company

A fictional energy company offers gas, electricity and hydrogen. Each energy type has its own COβ‚‚ factor used to calculate emissions per quote. These factors change annually based on new legislation.

Step-by-step breakdown

1

Create Custom Metadata Type

Energy_Factor__mdt with fields: Energietype__c (Text), CO2_Factor__c (Number).

2

Fill in metadata records

Add records for each energy type:

  • β€’ Gas: 1.8 kg COβ‚‚/mΒ³
  • β€’ Electricity: 0.4 kg COβ‚‚/kWh
  • β€’ Hydrogen: 0.0 kg COβ‚‚/kg
3

Build Flow for quote

The Flow retrieves the correct metadata record based on the chosen energy type and uses the COβ‚‚ factor to calculate total emissions.

4

Change factor in metadata

When the COβ‚‚ factor changes, you only adjust the metadata record. No redeployment, no Flow change – it works immediately.

Advantage: You keep one generic Flow. All energy-specific values are stored in Custom Metadata and manageable by admins.

Best Practices

Tips from CRM Force

Do use Custom Metadata for
  • βœ“Logic you want to centralize
  • βœ“Values you need across environments
  • βœ“Sharing between Flow and Apex
  • βœ“Configuration that rarely changes but is crucial
Don't use Custom Metadata for
  • βœ—Customer data or transactions
  • βœ—Data users change daily
  • βœ—Temporary campaigns or seasonal data
  • βœ—Data with complex relationships or large volumes

Want to discuss your Salesforce configuration?

We're happy to help you smartly use Custom Metadata, Flow and Apex for a scalable platform.