Skip to content
No results
Menu
No results
  • Home
  • All Blogs
    • Career
    • Admin
    • Developer
    • DevOps
    • CTA
  • Interview
  • Certifications
  • Free Training
  • About Us
Events
Apex Hours
  • Home
  • All Blogs
    • Career
    • Admin
    • Developer
    • DevOps
    • CTA
  • Interview
  • Certifications
  • Free Training
  • About Us
Courses
Events
Apex Hours
Courses

Access Custom Metadata Type Records Using Static Methods

  • Apex HoursWritten ByApex Hours
  • December 22, 2020
  • Salesforce Developer
  • February 7, 2025
  • 2 mins
Home Salesforce Developer Access Custom Metadata Type Records Using Static Methods

In the Salesforce Spring21 pre-release orgs there are new methods for Custom Metadata Types that mirror those on Custom Settings. Removes the need to query them via SOQL and drops the contribution to the Query Rows limit. Use the Apex getAll(), getInstance(recordId), getInstance(qualifiedApiName), and getInstance(developerName) methods to retrieve information from custom metadata type records faster. Let see how we can Access Custom Metadata Type Records Using Static Methods.

Table of contents
  1. What is Custom Metadata Type?
  2. getAll() to get Custom Metadata Type Records
  3. getInstance() to get Record

What is Custom Metadata Type?

The term “Metadata” is nothing but data about data. In simple words, when you create a record within Salesforce, you create data as well as metadata. The data which you are trying to enter, is captured or stored in the fields which are nothing but columns of your Object. 

Learn more about Custom Metadata Types.

These methods don’t rely on the SOQL engine and return the sObject details directly from the call.

  1. Removes the need to query them via SOQL
  2. Drops the contribution to the Query Rows limit.
  3. Another bonus with this approach is that it will pick up any field changes automatically as you aren’t explicitly requesting specific fields

Let see how we access the Custom Metadata Type records before Sprint 21

// Before Sprint 21
List<Email_Domain__mdt> listEmailDomain = [SELECT Id,MasterLabel,Domain__c from Email_Domain__mdt];
System.debug('--listEmailDomain->'+listEmailDomain);

getAll() to get Custom Metadata Type Records

Now let see how we can get Custom Metadata Type records with the getAll() method.

// Sprint 21 : get custom metadata with getAll
Map<String, Email_Domain__mdt> mapEd = Email_Domain__mdt.getAll();
for(String nameEmailDomain : mapEd.keySet()){
    System.debug('----->'+mapEd.get(nameEmailDomain).Domain__c);
}

getInstance() to get Record

What about if you don’t need to get all record and need to access only single record? In that case you can use the getInstance() method.

// Sprint 21 : get custom metadata with getInstance();
Email_Domain__mdt emailDomain = Email_Domain__mdt.getInstance('gmail');
System.debug('----->'+emailDomain);
Tags
# Custom Metadata Type
Share your love
Share on Facebook Share on X (Twitter) Share on Pinterest Share on LinkedIn
Apex Hours
Apex Hours

Salesforce Apex Hours is a program of the community, for the community, and led by the community. It is a space where Salesforce experts across the globe share their expertise in various arenas with an intent to help the Ohana thrive! Join us and learn about the apex hours team.

Articles: 357

Related Posts

LWC + Apex Best Practices for Large Data Operations

LWC + Apex Best Practices for Large Data Operations

getQueryLocator vs. Iterator in Apex

getQueryLocator vs. Iterator in Apex

Monitor Your Salesforce API Usage Like a Pro

Monitor Your Salesforce API Usage Like a Pro

How Revenue Cloud Helps Subscription

How Revenue Cloud Helps Subscription-Based Businesses

Salesforce Live Chat Migration Guide to Enhanced Chat

Salesforce Live Chat Migration Guide to Enhanced Chat

Apex Trigger Best Practices in Salesforce

Apex Trigger Best Practices in Salesforce

Leave a ReplyCancel Reply

Your email address will not be published. Required fields are marked *

Accelq

Important Links

Home
About us
Contact us
Privacy Policy

Recent Posts

  • Salesforce Data Breaches- What Really Went Wrong (And How to Protect Your Org)

  • From Admin to Architect —A Realistic Career Roadmap

  • LWC + Apex Best Practices for Large Data Operations

  • getQueryLocator vs. Iterator in Apex

  • Salesforce Revenue Cloud Key Objects We Should Know

Subscribe to the blog via email

Enter your email address to subscribe to this blog and receive notifications of new post by email.

Join 4,531 other subscribers

Copyright 2018-2026. All Rights Reserved By Apex Hours.