Latest Updates

Travel to Technology

Dayton Metro Library

Spring 21 - Accessing custom metadata types records from apex

 

In Spring 21 pre release, new methods introduced for Custom Metadata Types as like Custom Settings.

Following Methods

getAll() â€“ Will return the all records from Custom Metadata Type.

Before Spring 21:

list<Test_mdt> lstMetaDataRecords = [Select Id, MasterLabel from Test_mdt]

In Spring 21:

Map<String, Test__mdt> mapMetaDataRecords = Test__mdt.getAll();
list<Test_mdt> lstMetaDataRecords = mapMetaDataRecords.values();

getInstance() â€“ Will return a record from Custom Metadata Type.

In Spring 21:

Test_mdt objMetaDataRecord= Test_mdt.getInstance('test');