A realistic desktop mockup showing the Salesforce Setup home screen. The left sidebar highlights 'Custom Metadata Types' under Setup. The main panel displays a list view of existing CMDTs with columns like Label, API Name, and Visibility. Light background, professional UI style, no branding.

Custom Metadata Types Salesforce Guide

TABLE OF CONTENTS

Introduction

Custom Metadata Types in Salesforce (CMDTs) are one of the most powerful tools for building scalable, configurable applications. Unlike custom settings, CMDTs are deployable, packageable, and version-controlled, making them ideal for enterprise-grade Salesforce projects.

They allow you to define reusable configurations, business rules, feature toggles, and integration endpoints without hardcoding values. This guide explains what Custom Metadata Types are, how they differ from Custom Settings, their key use cases, setup process, and best practices.

What Are Custom Metadata Types in Salesforce?

 Alt text: Salesforce Setup showing Custom Metadata Types list in desktop mockup.

Custom Metadata Types (suffix __mdt) let you define application configuration as metadata. Both the type and its records can be deployed across environments.

  • They support fields, validation rules, and relationships.

  • CMDT records are cached at runtime, so retrieving them doesn’t count against SOQL governor limits.

  • They integrate seamlessly with Apex, Flow, and formulas, enabling both declarative and programmatic use.

Related reading: Salesforce Validation Rules Examples You Can Copy

Custom Metadata Types vs Custom Settings

FeatureCustom Metadata Types (CMDTs)Custom Settings
Deployable with recordsYesNo
Packageable for AppExchangeYesNo
Supports validation & formulasYesNo
Cached (no SOQL needed)YesNo
Best forReusable configurationOrg-specific values

For most Salesforce configuration metadata, CMDTs are the better option.

Related reading: Salesforce Record-Level Security

Key Use Cases of Custom Metadata Types

Custom Metadata Types in Salesforce go far beyond simple configuration. They allow admins and developers to store business rules, reference data, and environment-specific settings directly as metadata. This means values are not only reusable but also deployable across sandboxes, staging, and production environments without manual re-entry.

Whether you’re managing feature toggles, lookup tables, integration endpoints, or security rules, CMDTs provide a scalable and version-controlled solution that reduces hardcoding and simplifies maintenance.

1. Configuration & Feature Management

https://sdlccorp-web-prod.blr1.digitaloceanspaces.com/wp-content/uploads/2025/09/01180509/Untitled-design-54.webp.

CMDTs are perfect for feature toggles and environment-specific rules. Instead of editing Apex, you switch features on/off through CMDT records.

Related reading: Salesforce Approval Process: Step-by-Step Guide

2. Data Mappings & Lookup Tables

Salesforce CMDT records list for tax rate mapping in desktop mockup.

CMDTs can store reference data such as tax brackets, endpoint URLs, or region codes. This makes them reusable across orgs.

3. Integration with Apex, Flows, and Formulas

 Salesforce Developer Console showing Apex code using Custom Metadata Types
  • Apex: Access with getAll() and getInstance().

  • Flows: Reference CMDT values in automation.

  • Formulas: Use $CustomMetadata to replace hardcoded values.

Related reading:

4. Business Rules & Defaults

Store thresholds, limits, and default values in CMDTs for maintainable logic across orgs.

Related reading: Dynamic Forms vs Page Layouts: What to Use When

Step-by-Step Setup: Creating Custom Metadata Types

The advantages of AI in HR go beyond time savings. They shape strategy and workforce experience.

Step 1 — Create the CMDT

  Salesforce new Custom Metadata Type creation screen in desktop mockup.
  1. Go to Setup → Custom Metadata Types → New.

  2. Enter Label: Feature Toggle.

  3. Object Name: Feature_Toggle.

  4. Save.

Step 2 — Add Fields

  Salesforce new Custom Metadata Type creation screen in desktop mockup.

Add custom fields such as:

  • Feature_Key__c (Text)

  • Is_Enabled__c (Checkbox)

  • Description__c (Text Area)

Step 3 — Set Visibility

  Salesforce new Custom Metadata Type creation screen in desktop mockup.
  • Public: Usable across subscriber orgs.

  • Protected: Restricted to package namespace.

Step 4 — Create Records

Salesforce CMDT manage records screen for Feature Toggle in desktop mockup.

Click Manage Records and add entries like:

  • Checkout_DiscountsIs_Enabled = TRUE

  • Beta_UXIs_Enabled = FALSE

Step 5 — Use CMDT in Apex

Salesforce Developer Console showing Apex code using CMDT getInstance.

CMDTs can be accessed in Apex without SOQL (faster, doesn’t consume governor limits).

Example 1: Single record

 
Feature_Toggle__mdt betaUX = Feature_Toggle__mdt.getInstance('Beta_UX'); if (betaUX != null && betaUX.Is_Enabled__c) { System.debug('Beta UX feature is enabled!'); } else { System.debug('Beta UX feature is disabled.'); }

Example 2: All records

 
Map<String, Feature_Toggle__mdt> toggles = Feature_Toggle__mdt.getAll(); if (toggles.get('Checkout_Discounts') != null && toggles.get('Checkout_Discounts').Is_Enabled__c) { System.debug('Checkout Discounts are active!'); }

Example 3: SOQL (for long text fields)

 
List<Feature_Toggle__mdt> toggles = [ SELECT DeveloperName, Feature_Key__c, Is_Enabled__c, Description__c FROM Feature_Toggle__mdt ]; for (Feature_Toggle__mdt toggle : toggles) { System.debug('Feature: ' + toggle.DeveloperName + ' Enabled: ' + toggle.Is_Enabled__c); }

Step 6 — Use CMDT in Formulas & Flows

Salesforce Flow Builder referencing Custom Metadata Types in desktop mockup.

Formula Example

 
$CustomMetadata.Feature_Toggle__mdt.Checkout_Discounts.Is_Enabled__c

👉 Useful for validation rules or default values.

Flow Example

  1. Create a Flow.

  2. Add a Decision Element.

  3. Reference $CustomMetadata.Feature_Toggle__mdt.

  4. Choose Is_Enabled__c for decision logic.

 Flows can now change behavior based on metadata.

Step 7 — Test CMDTs in Apex

Salesforce Apex test class using CMDT in desktop mockup.

CMDTs are available by default in tests.

 
@isTest private class FeatureToggleTest { @isTest static void testBetaUXToggle() { Feature_Toggle__mdt betaUX = Feature_Toggle__mdt.getInstance('Beta_UX'); System.assertEquals(false, betaUX.Is_Enabled__c, 'Beta UX should be disabled by default'); } }

Step 8 — Deploy CMDTs Across Environments

Salesforce Change Set screen showing deployment of CMDT in desktop mockup..
  • Change Sets → point-and-click migration.

  • Salesforce CLI (sfdx) → for CI/CD pipelines.

  • Unlocked Packages → best for large teams.

 Always deploy CMDT + records together.

Related reading: Salesforce Sandbox Refresh Best Practices for 2025

Best Practices for Custom Metadata Types

Desktop mockup of Salesforce dashboard showing a checklist of best practices for Custom Metadata Types..
  • Name fields clearly → e.g., Feature_Key__c.

  • Keep CMDTs lightweight → only store values needing deployment.

  • Use static accessors in Apex → avoid unnecessary queries.

  • Add validation rules → prevent incorrect metadata.

  • Version-control metadata → commit CMDTs to Git with other metadata.

Related reading: Salesforce Sandbox Refresh Best Practices for 2025

Benefits of Using Custom Metadata Types

 Salesforce desktop mockup showing dashboard panel listing benefits of Custom Metadata Types such as scalability, maintainability, performance, and flexibility.
  • Scalability → works across orgs and packages.

  • Maintainability → avoids hardcoding.

  • Performance → cached, no SOQL needed.

  • Flexibility → usable in Apex, Flows, Formulas.

Conclusion

Salesforce Custom Metadata Types give developers and admins a powerful way to manage configurations declaratively. They reduce code maintenance, improve scalability, and help enforce governance.

For feature toggles, mappings, integration settings, and reusable business rules, CMDTs should be your go-to choice.

Related reading: Understanding Salesforce Page Layouts vs Dynamic Forms

FAQs

Q1: What are Custom Metadata Types in Salesforce?

Custom Metadata Types (CMDTs) are metadata objects (__mdt) used to store configuration as metadata. They help developers and admins manage reusable values, rules, and settings that can be deployed across orgs.

CMDTs are deployable with records, packageable, and support validation rules and formulas. Custom Settings are limited to org-specific data, making CMDTs the better choice for scalable configuration.

CMDTs are best for feature toggles, lookup tables, integration endpoints, business rules, and environment-specific settings. They remove hardcoding and improve governance.

Yes. CMDTs can be accessed using getAll() or getInstance() methods in Apex without consuming SOQL queries. For long text fields, you can use SOQL queries on __mdt objects.

 

CMDTs can be referenced in Flows via Decision Elements and in formulas using $CustomMetadata. This allows admins to configure automation without hardcoding values.

 

Yes. Custom Metadata Types are available in Enterprise, Performance, Unlimited, and Developer editions.

 

Yes. Custom Metadata Types are available in Enterprise, Performance, Unlimited, and Developer editions.

Facebook
Twitter
Telegram
WhatsApp

Subscribe Our Newsletter

Request A Proposal

Contact Us

File a form and let us know more about you and your project.

Let's Talk About Your Project

Responsive Social Media Icons
Contact Us
For Sales Enquiry email us a
For Job email us at
sdlc in USA

USA:

166 Geary St, 15F,San Francisco,
California,
United States. 94108
sdlc in USA

United Kingdom:

30 Charter Avenue, Coventry CV4 8GE Post code: CV4 8GF
United Kingdom
sdlc in USA

Dubai:

P.O. Box 261036, Plot No. S 20119, Jebel Ali Free Zone (South), Dubai, United Arab Emirates.
sdlc in USA

Australia:

7 Banjolina Circuit Craigieburn, Victoria VIC Southeastern
 Australia. 3064
sdlc in USA

India:

715, Astralis, Supernova, Sector 94 Noida Delhi NCR
 India. 201301
sdlc in USA

India:

Connect Enterprises, T-7, MIDC, Chhatrapati Sambhajinagar, Maharashtra, India. 411021
sdlc in USA

Qatar:

B-ring road zone 25, Bin Dirham Plaza building 113, Street 220, 5th floor office 510 Doha, Qatar

© COPYRIGHT 2024 - SDLC Corp - Transform Digital DMCC