8

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?

1 Answer 1

15

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
6
  • Thank you! I searched for hours trying to find this information. You've explained this perfectly.
    – Mr. K
    Apr 17, 2017 at 18:07
  • 7
    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, 2017 at 19:47
  • 1
    +1 for the Apex Query example. The Apex use is not documented well, but makes sense since it's a Relationship. Jul 21, 2017 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? Mar 26, 2019 at 8:17
  • 1
    You can now (at least sometime after this answer was written) query FieldDefinition directly in SOQL SELECT Id, QualifiedApiName FROM FieldDefinition WHERE DurableId = :myMdtRow.Controlling_Field__c
    – cropredy
    Aug 10 at 1:59

You must log in to answer this question.

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