Custom metadata types versus custom settings
How to choose between custom metadata types, list custom settings and hierarchy custom settings, read them without spending SOQL, write custom metadata from Apex, protect secrets in packages and avoid the test and query traps each one sets.
Given a scenario, identify best practices for various types of custom metadata and custom settings, and how to implement required solutions.
~8 min read · 15 practice questions ·
What the exam expects
- Choose a custom metadata type, a list custom setting or a hierarchy custom setting from a requirement about deployment, per-user values, relationships or secrecy.
- Read each one in Apex without spending SOQL queries, and know when a query does count or a value is truncated.
- Update custom metadata records from Apex through the Apex Metadata API instead of DML.
- Protect secrets with protected custom metadata in a managed package, and pass custom metadata safely to components.
- Predict how tests see custom metadata and custom settings, and which declarative features can reference them.
Key terms: custom metadata type (__mdt: an object whose records are metadata, deployed with the app), list custom setting (cached org-wide data sets), hierarchy custom setting (cached values resolved user → profile → org), Apex Metadata API (the Metadata namespace that deploys custom metadata records), protected (visible only to code in the package's namespace).
Key facts
- Detail
- Not deployable; only the definition moves
- Detail
- Unlimited, except long text area fields and flows
getAll() / getInstance() on __mdt- Detail
- First 255 characters per field only
- Detail
- Skips the application cache, like a custom object query
- Detail
- Not supported; create and update only (subscriber-controlled, visible records)
- Detail
- Hierarchy only, via
$Setup
- Detail
- 200, plus 150 more from certified managed packages
- Detail
- Lesser of 20 MB or 2 MB per full-featured license
Sources for this section (7)
- Get Started with Custom Metadata Typestrailhead.salesforce.com (opens in a new tab)
- Custom Metadata Allocations and Usage Calculationshelp.salesforce.com (opens in a new tab)
- Custom Metadata Type Methodsdeveloper.salesforce.com (opens in a new tab)
- Custom Settings Methodsdeveloper.salesforce.com (opens in a new tab)
- Develop and Test with Custom Metadata Typestrailhead.salesforce.com (opens in a new tab)
- Access Custom Settings with Codehelp.salesforce.com (opens in a new tab)
- Custom Settings Limits and Considerationshelp.salesforce.com (opens in a new tab)
- Why does `getInstance()` on a custom metadata type cut off a 2,000-character body?
- When should a developer choose a hierarchy custom setting over a custom metadata type?
- Why can't a custom metadata query use `OR` across `Country__c` and `Product_Line__c`?
- How does Apex change a custom metadata record at run time?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the Platform Developer II pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 28 lessons of the Platform Developer II guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Inline practice questions and one-click topic practice (15 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams