I’m trying to use Custom metadata type to replace a List type Custom settings. I have to access the Custom metadata type information in multipe apex classes and triggers.
When I use custom settings, I can access them from apex using,
List<customSettingsObject__c> cs = customSettingsObject__c.getall().values();
I dont have to use a SOQL Query for custom settings.
But to access Custom metadata type in apex, I have to use a soql,
List<custMetadataType__mdt> mcs = [select id,MasterLabel from custMetadataType__mdt];
I don’t want to query since I have to use it in multiple classes and triggers.
Any other way to access Custom metadata type in apex without SOQL?
Answer
No, you must access them with a SOQL statement. However, SOQL queries against custom metadata do not increase the SOQL queries governor limit counter nor the SOQL query rows governor limit counter, so you can query them as frequently as you like.
Attribution
Source : Link , Question Author : Anurag , Answer Author : sfdcfox