[SalesForce] Custom Metadata Types – RecordType

I have created a Custom Metadata Type that has a field with a relationship to EntityDefinition(object).

This EntityDefinition here suggests a field RecordTypes, but it is available only in the Tooling API, which does not support Custom Metadata Types. I can work around it by querying the record types with the object name I get from EntityDefinition, but I was thinking if there is a more direct approach to it.

Thoughts, please.

Best Answer

First of all, RecordTypes is a relationship name, not a field:

Represents the record types defined for this object. Use only in subqueries. This field is available in Tooling API version 34.0 and later. Because this field represents a relationship, use only in subqueries.

Secondly, if you're querying the Custom Metadata Type, you will need either a separate query for the record types, or you can use a DescribeSObject call instead. SOQL doesn't support querying the children of parent records (e.g. you cannot say SELECT (SELECT ... FROM CustomLookup__r.Children__r) FROM Object__c. Consider using the describe call to save on governor limits.