0

I'm reading the answer to this following question:

How to get a field's API name when querying a field of datatype, Metadata Relationship(Field Definition)

However, when I run the following query in execute anonymous (Request Type is a field definition):

System.debug([SELECT Request_Type__r.QualifiedApiName FROM Health_Cloud_Integration_Settings__mdt LIMIT 1]);

I get the following:

14:44:07:832 USER_DEBUG [2]|DEBUG|(Health_Cloud_Integration_Settings__mdt:{Request_Type__c=Case.00N0J000003sOFL, Id=m0O5E000000CeFjUAK})

Why can't I get the API name of a field definition from a Custom Metadata Type?

If I run the query in Query Editior, it works fine, and returns the qualified api name.

2

You are debugging using string coercion, which leaves you at the mercy of how the debugger converts your records to strings. If you want to see the values of cross object fields, you can loop through and debug the value of that field, query in the Query Editor, or export the results via various tools like Data Loader.

for (My_Metadata__mdt record : [SELECT ... FROM ...])
    system.debug(record.Field__r.QualifiedApiName);
2
  • Hm. I'm trying to a similar query as your answer, but I'm passing a list of Fields dynamically, and I suspect the same thing is happening. Thanks for your answer. – MetadataLater May 1 '20 at 14:04
  • May be worth noting the performance implications of using entity and field definitions in custom metadata types discussed in this answer and the comments on it. – Phil W May 1 '20 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.