1

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.

1 Answer 1

2

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.

5
  • Thanks @sfdcfox, I am sure I can do a DescribeSobject and retrieve the recordtypes but is there a way to query it using EntityDefinition's RecordTypes? When I turned on 'Tooling API' and queried cmd types from the dev console, it errored out as Tooling API does NOT support cmd types. From the text you have put in your comments, RecordTypes needs Tooling API, so is it possible to use RecordTypes at all in combination with cmd types ?
    – SF Learner
    Mar 19, 2018 at 8:43
  • 1
    @ShaliniSF Again, no, SOQL doesn't support this. If you were querying the EntityDefinition directly, using the Tooling API, it would be allowed. But starting from the Custom Metadata Type, you won't be able to do so, since EntityDefinition doesn't exist in the standard SOAP API.
    – sfdcfox
    Mar 19, 2018 at 8:54
  • @sfdxfox, Thanks for the explanation. Looks like Describe is the only way.
    – SF Learner
    Mar 19, 2018 at 11:10
  • one last question related to EntityDefinition: Can there be duplicates EntityDefiniton values across records? I am trying to create 2 records with EntityDefiniton value as 'Contact' and the system complains 'Duplicate value on record'. Documenation on Entitydefinition is very limited on the net,so can you pls clarify why there is such restriction?
    – SF Learner
    Mar 19, 2018 at 11:52
  • @ShaliniSF Yes, it's allowed. However, the name field for each record must be unique, which is what you are probably seeing.
    – sfdcfox
    Mar 19, 2018 at 14:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .