How to return map containing custom metadata type records for the specific custom metadata type in Salesforce?

How to return map containing custom metadata type records for the specific custom metadata type in Salesforce?

getAll() method can be used. 

1. Create a Custom Metadata Type.

2. Create few records.

Sample Code:

Map < String, Test__mdt > mapCustomMetadataType = Test__mdt.getAll();

for ( String strKey : mapCustomMetadataType.keySet() ) {
    
    system.debug( 'Key is ' + strKey );
    system.debug( 'Custom Metadata Type record is ' + mapCustomMetadataType.get( strKey ) );
    
}

Output:

Leave a Reply