3

In SOQL ,I do not understand the return value when selecting a field of type Metadata Relationship(Field Definition).

In my custom metaData type

  • "controllingObject__c" is of dataType ,Metadata Relationship(Entity Definition)
  • "controllingField__c" is of dataType, Metadata Relationship(Field Definition)

Right now I have one record of this type where

  • controllingObject__c =Account
  • controllingField__c = Account.tier__c (which is a text field)

Here is my SOQL query:

SELECT controllingObject__c, controllingField__c FROM My_Custom_MetaDataType__mdt

controllingObject__c returns "Account" but controllingField__c returns "Account.00N3600000RSyBA".

What is this value? It looks like some type of ID but I didn't think fields had any kind of unique Identifier other than their API Name. Is there a way I can get the API Name of the field from this value?

8

The 00N prefix is the CustomField metadata object. Unlike the API name, the field's ID will never change once created. You can query this using the Tooling API:

SELECT DeveloperName FROM CustomField WHERE Id = '00N...'

You'll need to strip the object name off the front of the string before you query it. The DeveloperName field will be the API Name.

Standard fields will be referenced by name when you query them from the metadata object, and do not require a separate query to the get the related API name.

You should also be aware that selecting a custom object will use the CustomObject ID (01I prefix). You can also query this object via the Tooling API.

Alternatively, you can also request the API name in the metadata query:

select controllingobject__r.developername, controllingfield__r.developername from My_Custom_MetaDataType__mdt
  • Thank you! I searched for hours trying to find this information. You've explained this perfectly. – Mr. K Apr 17 '17 at 18:07
  • 2
    I ended up using QualifiedApiName which I found on this page of the Tooling API guide instead of FullName because FullName doesn't include the "__c" – Mr. K Apr 17 '17 at 19:47
  • +1 for the Apex Query example. The Apex use is not documented well, but makes sense since it's a Relationship. – Scott Pelak Jul 21 '17 at 19:54
  • @sfdcfox For custom field we will have Id but if I want to get the details of a standard field then how can I get that? – Dilip Irabatti Mar 26 at 8:17
  • @DilipIrabatti You can use a describe call to get standard fields. This answer only addresses the situation when you get an ID and want to figure out the field. – sfdcfox Mar 26 at 13:04

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.