function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
boBNunnyboBNunny 

Custom Metadata - Create MAP of all entries

When querying Custom Metadata, is there a simple method to getting a MAP of DeveloperName to the record so it can be retrieved by a single name?  Custom Settings has this, but doing a standard MAP/SOQL gives the ID to the record instead of the DeveloperName.
Best Answer chosen by boBNunny
boBNunnyboBNunny
Found my own answer.  There are specific methods for Custom MDT objects.

Set<String> mdtNames = CustomMetadata.SFDC_Health_Check__mdt.getAllNames();
Map<String, CustomMetadata.SFDC_Health_Check__mdt> cmdMap = CustomMetadata.SFDC_Health_Check__mdt.getByNames(mdtNames);

Will get the MAP I was looking for.  Could make it one line, but would be confusing then I think.
Map<String, CustomMetadata.SFDC_Health_Check__mdt> cmdMap = CustomMetadata.SFDC_Health_Check__mdt.getByNames(CustomMetadata.SFDC_Health_Check__mdt.getAllNames());
 

All Answers

boBNunnyboBNunny
Found my own answer.  There are specific methods for Custom MDT objects.

Set<String> mdtNames = CustomMetadata.SFDC_Health_Check__mdt.getAllNames();
Map<String, CustomMetadata.SFDC_Health_Check__mdt> cmdMap = CustomMetadata.SFDC_Health_Check__mdt.getByNames(mdtNames);

Will get the MAP I was looking for.  Could make it one line, but would be confusing then I think.
Map<String, CustomMetadata.SFDC_Health_Check__mdt> cmdMap = CustomMetadata.SFDC_Health_Check__mdt.getByNames(CustomMetadata.SFDC_Health_Check__mdt.getAllNames());
 
This was selected as the best answer
ShaminaShamina
@boBNunny

The  "CustomMetadata" keyword is not recognized when executing the above code for a custom metadata type in my org.
Set<String> mdtNames = CustomMetadata.CustomData__mdt.getAllNames();

Generates error: COMPILE ERROR: Method does not exist or incorrect signature: CustomMetadata.CustomData__mdt.getAllNames()
Any idea how to make this work?
I have checked in online documentation, but could not find any mention of these methods of accessing custom metadata type records

Thanks