I am new to custom metadata types (CMDT). With the Winter'22 maintenance, I learned that there is no longer a need to write Salesforce Object Query Language (SOQL) to access custom metadata records in Apex. There are new methods similar to accessing Custom Settings. This removes any SOQL limits, making the code cleaner and faster.
However, the example shown for this on the trailhead module uses
Games__mdt mc = Games__mdt.getInstance('FirstRecord');
to return a single record sObject. FirstRecord
is the developerName for the CMDT named Games_mdt
I am interested in learning good practices with Apex and I am curious to know:
- Is hard coding CMDT names in Apex a good practice?
- If so, please explain why?
- If not, how do I avoid hard coding CMDT name?