In this blog, we will explore Custom Metadata Types in detail. You will learn what they are, their key features, how to create and use them, and why they are an essential tool for building dynamic and scalable applications on the Salesforce platform.
Table of Contents
What is Custom Metadata in Salesforce?
Custom Metadata in Salesforce is a tool used to store configuration and management data. Unlike Custom Settings, Custom Metadata records are part of the metadata, meaning they can be deployed between environments using change sets or metadata API tools. This makes them ideal for creating reusable and easily deployable configurations.
Key Features of Custom Metadata
- Deployable and Upgradable: You can package and deploy them between orgs.
- Limitless Usability: Governed by metadata limits instead of standard DML limits.
- SOQL Query Support: Retrieve records using SOQL queries.
- Protected and Public Records: Control record visibility with fine-grained options.
- Supports Relationships: Create lookup fields to other metadata types or objects.
Field Types in Custom Metadata: A Quick Overview
- Text – Stores alphanumeric characters.
- Long Text Area – Stores up to 32,768 characters.
- Rich Text Area – Stores formatted text with rich formatting.
- Number – Stores numeric values with decimal places.
- Currency – Stores currency values.
- Checkbox – Stores Boolean (True/False).
- Date/Time – Stores date and time values.
- Date – Stores date values.
- Date/Time – Stores date and time values.
- Picklist – Stores a predefined list of values.
- Picklist (Multi-Select) – Allows multiple selections.
- Formula – Calculates a value based on other fields.
- External Lookup – Links to an external object.
- Lookup – Links to another Salesforce object.
- Encrypted Text – Stores encrypted sensitive text.
How to Use Custom Metadata
Create a Custom Metadata Type:
- Go to Setup → Custom Metadata Types → New Custom Metadata Type.

- Define the label, visibility, and optional fields then click on Save button.

Insert Metadata Records: Metadata records can be created using the following methods:
- Salesforce UI: Navigate to the Custom Metadata Type in Setup, select Manage [Metadata Label]

- click “New” to create a record.

- provide all details and click on Save button .

- The record has been created successfully.

- Apex Code: Insert records programmatically using Apex:
My_Metadata_Type__mdt record = new My_Metadata_Type__mdt();
record.DeveloperName = 'Record_Name';
record.MasterLabel = 'Record Label';
record.Custom_Field__c = 'Value';
insert record;
Access in Apex: Retrieve and use metadata in Apex with SOQL queries. For example:
List<My_Metadata_Type__mdt> metadataRecords = [SELECT DeveloperName, FieldName__c FROM My_Metadata_Type__mdt];
Important Methods for Custom Metadata in Apex
- SOQL Queries: Fetch records:
SELECT DeveloperName, Field1__c FROM Custom_Metadata_Type__mdt
2. Access Field Descriptions: Use the Schema
class for dynamic handling.
Map<String, Schema.SObjectField> fields = Schema.SObjectType.Custom_Metadata_Type__mdt.fields.getMap();
Benefits of Custom Metadata
- Reusability: Store reusable application logic and constants.
- Deployment Ready: Easily migrate configurations between orgs.
- No Governor Limits: Metadata records are not subject to DML and query limits.
- Efficiency: Perfect for settings that change rarely and are used in multiple places.
Key Differences Between Custom Metadata and Custom Settings
Feature | Custom Metadata | Custom Settings |
---|---|---|
Deployable | Yes, via metadata API or Salesforce DX | No, must be manually recreated in each org |
Queryable via SOQL | Yes | Yes |
Access in Apex | CustomMetadata.getAll() | CustomSettings.getInstance() |
Customizable at Runtime | No, must be set during deployment | Yes, can be updated at runtime |
Types | Only one type | List and Hierarchy types |
Use Case | Configuration settings, deployment-ready | User or profile-specific settings |
Summary
Custom Metadata in Salesforce helps store deployable, consistent configuration data across environments. It’s ideal for managing static settings like app configurations and integration keys, offering flexibility and easy access via Apex.