Skip to content
  • Home
  • All Blogs
  • LWC
  • Apex
  • Interview
  • About Us
The Ultimate Guide to Custom Metadata in Salesforce

The Ultimate Guide to Custom Metadata in Salesforce

December 27, 2024 by ApexVine

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?
  • Key Features of Custom Metadata
  • Field Types in Custom Metadata: A Quick Overview
  • How to Use Custom Metadata
    • Create a Custom Metadata Type:
    • Important Methods for Custom Metadata in Apex
  • Benefits of Custom Metadata
  • Key Differences Between Custom Metadata and Custom Settings
    • Summary

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

  1. Deployable and Upgradable: You can package and deploy them between orgs.
  2. Limitless Usability: Governed by metadata limits instead of standard DML limits.
  3. SOQL Query Support: Retrieve records using SOQL queries.
  4. Protected and Public Records: Control record visibility with fine-grained options.
  5. 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

  1. 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

FeatureCustom MetadataCustom Settings
DeployableYes, via metadata API or Salesforce DXNo, must be manually recreated in each org
Queryable via SOQLYesYes
Access in ApexCustomMetadata.getAll()CustomSettings.getInstance()
Customizable at RuntimeNo, must be set during deploymentYes, can be updated at runtime
TypesOnly one typeList and Hierarchy types
Use CaseConfiguration settings, deployment-readyUser 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.

Categories Apex Tags Custom Metadata, Custom Metadata Fields, Custom Metadata Types, Salesforce Configuration, Salesforce Custom Metadata
The Ultimate Guide to Custom Settings in Salesforce
The Ultimate Guide to HTTP Status Codes for Salesforce Callouts
© 2025 • Built with GeneratePress