Intermediate 25 min read

Custom Metadata Types

By the end of this lesson, you'll be able to:

  • Explain what custom metadata is and how it differs from custom settings
  • Query custom metadata records using SOQL
  • Recognize deployability as custom metadata's key advantage

Prerequisites: "Hierarchy Custom Settings"

Configuration that deploys like code

Custom settings and regular records both live purely in an org's data — they don't automatically move when code is deployed from a sandbox to production. Custom metadata records are different: they're treated as metadata, the same category as an Apex class or a custom field, meaning they deploy right alongside code changes.

Querying custom metadata

List<Discount_Rule__mdt> rules = [
    SELECT Label, Discount_Percent__c, Minimum_Order_Amount__c
    FROM Discount_Rule__mdt
];

for (Discount_Rule__mdt rule : rules) {
    System.debug(rule.Label + ': ' + rule.Discount_Percent__c + '%');
}

Custom metadata's API name ends in __mdt (rather than __c), and — unlike list custom settings — it's queried with regular SOQL syntax, just like any object from Module 20. It doesn't hit the cached-read path custom settings use, but it gains something custom settings can't offer: deployability.

Why deployability matters

Imagine a set of discount rules that must be identical across a sandbox and production, tested together with the Apex logic that reads them. Custom metadata records travel in the same deployment as that Apex code — a change set or package includes both together, staying in sync. A custom setting's values, by contrast, would need to be manually re-entered (or migrated with a separate data tool) in every environment.

Exercise

Write a SOQL query selecting Label and Discount_Percent__c from a custom metadata type Discount_Rule__mdt.

Show hint

The API name ends in __mdt, queried like any other SOQL object.

APEX

Custom Metadata Types Quiz

1. What is custom metadata's key advantage over custom settings?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

Custom metadata records behave like configuration data but are deployable — moving with a change set or package the same way Apex code does, unlike custom settings or regular records.