Skip to content

Centricity Force

A tech enthusiast, focused in Salesforce, Devops, AI, Data

  • Home
  • Contact

Tag: Custom Metadata

Access Custom Metadata Type Records without SOQL

List<MyCustomMetadata__mdt> mcm = MyCustomMetadata__mdt.getall().values();
String myFieldValue = mcm[0].MyField__c;

getAll() – Returns a map containing custom metadata records for the specific custom metadata type. The map’s keys are the IDs (as String) of the records and the map’s values are the record sObjects.

getInstance(recordId) – Returns a single custom metadata type record sObject for a specified record ID.

getInstance(developerName) – Returns a single custom metadata type record sObject for a specified developerName field of the custom metadata type object.

getInstance(qualifiedApiName) – Returns a single custom metadata type record sObject for a qualified API name.

Example

This sample returns a single record sObject for the custom metadata type named Games_mdt with developerName specified as FirstRecord.

Games__mdt mc = Games__mdt.getInstance('FirstRecord');

Example with an Apex Class

public class CountryCodeHelper {
    public static String getCountryCode(String country) {
        Country_Code__mdt countryCode = Country_Code__mdt.getInstance('Canada');
        return countryCode.Country_Code__c;
    }
}
Unknown's avatarAuthor Jyotirmay PaulPosted on April 24, 2021December 22, 2022Tags Custom Metadata, SalesforceLeave a comment on Access Custom Metadata Type Records without SOQL

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 5 other subscribers
  • Home
  • Contact
Centricity Force Blog at WordPress.com.
  • Subscribe Subscribed
    • Centricity Force
    • Already have a WordPress.com account? Log in now.
    • Centricity Force
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar