3

Hi I would like to know how I can query the "Where is this used" relationship via SOQL. Generally, Metadata information on Fields can be found in FieldDefinition and Entity Particle tables, but can the new functionality be queried yet? If not, can I get the info by code, I think Apex DescribeFieldResult does not have apropriate methods...

3

Yes, after winter20 release we can query metadata decencies using tooling API. So while running this query, "Use Tooling API" checkbox must be checked in developer console.

SELECT MetadataComponentName, MetadataComponentType
FROM MetadataComponentDependency
WHERE RefMetadataComponentType = 'ApexClass'
AND MetadataComponentId = '00NXXXXXXXXXXXXXXX'
1
  • Ok, that seems to be it. In order to see the relations you have to add the "Ref" fields: SELECT MetadataComponentName, MetadataComponentType, MetadataComponentId, RefMetadataComponentId, RefMetadataComponentName, RefMetadataComponentType FROM MetadataComponentDependency Oct 11 '19 at 13:36
0

Here's some documentation for you: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_metadatacomponentdependency.htm

As someone already mentioned, you can query it using Tooling API.

0

You cannot do the "Where is this used" query against the MetadataComponentDependency object for out-of-the-box fields like Account.Name at this time. You can do it for custom fields.

You can do these queries through the Developer Console's Query Editor if you check the "Use Tooling API" checkbox. You can also use the REST API, for example, through the Workbench REST Explorer.

STEPS:

  1. Get your SObject Id. For out-of-the-box SObjects like Account, the Id is just the SObject name, e.g. "Account". You can find custom SObject Ids with this tooling query: SELECT Id, DeveloperName FROM CustomObject. The corresponding REST API path is: /services/data/v48.0/tooling/query?q=SELECT+Id,DeveloperName+FROM+CustomObject

  2. Use that Id to get your SObject's fields: SELECT Id, DeveloperName FROM CustomField WHERE TableEnumOrId = 'Account'. The corresponding REST API path is: /services/data/v48.0/tooling/query?q=SELECT+Id,+DeveloperName+FROM+CustomField+WHERE+TableEnumOrId+=+'Account'

  3. Finally, use one or more of those fields' Id values to view usage. Here is a sample query for CustomField with the made-up Id value of 00N123456789012AAA: SELECT Id, MetadataComponentId, MetadataComponentNamespace, MetadataComponentName, MetadataComponentType, RefMetadataComponentId, RefMetadataComponentNamespace, RefMetadataComponentName, RefMetadataComponentType FROM MetadataComponentDependency WHERE RefMetadataComponentId IN ('00N123456789012AAA'). The corresponding REST API path is: /services/data/v48.0/tooling/query?q=SELECT+Id,+MetadataComponentId,+MetadataComponentNamespace,+MetadataComponentName,+MetadataComponentType,+RefMetadataComponentId,+RefMetadataComponentNamespace,+RefMetadataComponentName,+RefMetadataComponentType+FROM+MetadataComponentDependency+WHERE+RefMetadataComponentId+IN+('00N123456789012AAA')

Part of the reason I have provided those REST API paths is because the Developer Console Query Editor never returns more than one row for me for that final query. (It will say it has many "Total Rows", but then it displays only one.)

1
  • For the Developer Console Query issue you mention, try removing "Id" from the list of columns you are querying. Many of the Tooling API SObjects (and MetadataComponentDependency appears to be one of them) don't have a real Id column, and will return the "null" id of "000000000000000AAA" for every row, in which case Dev Console will only display the first row. Removing it should allow you to see all rows of the result.. Nov 29 '20 at 3:56

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.