Custom Metadata Methods

“Custom Metadata Settings” with Spring 21 finally got the same methods as their sibling “Custom Settings”. They’re basically the same except with one exception: getValues method got renamed to getInstance for Custom Metadata Settings. Also the __c got replaced with __mdt for the object name, the rest is pretty much the same except for the bigger differences between the two.

// This method loads all of the custom settings in to a list:
list<Customer_Setting_Name__mdt> buList = Customer_Setting_Name__mdt.getall().values();

// And finally, this method loads all of the custom settings in to a map with the name as the key:
Map<String,Customer_Setting_Name__mdt> buMap = Customer_Setting_Name__mdt.getAll();

// This method loads a record using the name as a filter.
Customer_Setting_Name__mdt aplo = Customer_Setting_Name__mdt.getInstance(filter_string); 

Leave a Reply

Your email address will not be published. Required fields are marked *