Skip to content
SFDCian – Best Salesforce Consultant & Architect
  • Home
  • My Salesforce Implementation
  • Training Programs
  • Articles
    • Zendesk to Salesforce Service Cloud Migration
    • Apex
    • Apex Coding Best Practice
    • Apex Trigger Execution
    • How to become an Architect
  • About
  • Contact
Search
SFDCian – Best Salesforce Consultant & Architect
  • Home
  • My Salesforce Implementation
  • Training Programs
  • Articles
    • Zendesk to Salesforce Service Cloud Migration
    • Apex
    • Apex Coding Best Practice
    • Apex Trigger Execution
    • How to become an Architect
  • About
  • Contact

Retrieve Custom Metadata Without Extensive Queries – Spring ’21

/ apex, Salesforce / By Ayub

Up until the Winter ’21 release, whenever we needed to retrieve all or specific entries of Custom Metadata Types, we had to construct a comprehensive query.

It typically appeared like this:

List<Location__mdt> locationMetadata = [SELECT field1, field2 on Location__mdt];

Now, as part of this release, the process of interacting with Custom Metadata Types has been streamlined for the better.

Two new methods have been introduced with this release:

  • getAll()
  • getInstance() – This method takes a single parameter, which can be either the record ID, developer name, or qualified API name.
//this give us access to all the records in the custom metadata types
List<Location__mdt> loc = Location__mdt.getAll();

//this give us access to the record that's associated with the provided record ID
List<Location__mdt> loc = Location__mdt.getInstance();

//this give us access to the record that's associated with the provided DeveloperName
List<Location__mdt> loc = Location__mdt.getInstance('DeveloperName');

//this give us access to the record that's associated with the provided QualifiedApiName
List<Location__mdt> loc = Location__mdt.getInstance('QualifiedApiName');


That’s quite convenient, isn’t it!

This ensures that the approach to interacting with both Custom Settings and Custom Metadata adheres to the same standards.

Post navigation
← Previous Post
Next Post →

Related Posts

Salesforce: Clone Opportunity with Products & Contact Role

Salesforce, Uncategorized / By Ayub

Are you building lightning app with Locker Services!!!

Salesforce, Uncategorized / By Ayub
Email

Learn

  • Home
  • Request For Services
  • Apex Trigger Practice
  • Tooling API
  • Blog
  • Write For Us
  • Privacy Policy

Copyright © 2025 SFDCian - Best Salesforce Consultant & Architect | Powered by SFDCian - Best Salesforce Consultant & Architect