I am looking for a SOQL query that can display where a particular field is being referenced in Salesforce. Salesforce already has a button called "Where is this used?" for custom fields that displays all the field references. How would I write that function as a SOQL query?

2 Answers 2


Related to the previous post here is the sample query you can run in Developer Console with 'Use Tooling API' enabled in Query Editor.

SELECT MetadataComponentType, MetadataComponentName, RefMetadataComponentName, RefMetadataComponentId
FROM MetadataComponentDependency
WHERE RefMetadataComponentId = 'fieldId' AND RefMetadataComponentType = 'CustomField'
ORDER By RefMetadataComponentName

You need some way of getting FieldId though to filter by RefMetadataComponentId.

In SOQL you can't execute it because it doesn't support ToolingApi. In order to do so you need to do HttpRequest to Tooling API.

As an example you can use this post Tooling API usage in salesforce Apex method

Here is a link to documentation https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/intro_rest_resources.htm

Use this endpoint /services/data/${API_VERSION}/tooling/query/?q=

UPDATE thanks Jeff for the Field Query.

You can use this field to get Id for particular field

FROM CustomField 
WHERE FullName = 'Object_Api_Name__c.Field_Api_Name__c'
  • 1
    If you are looking for references to a Custom Field, you can use the same Tooling API to query the CustomField object to get the Id reference you'll find in the RefMetadataComponentId and MetadataComponentId fields for CustomFields: select Id from CustomField where FullName = 'Object_Api_Name__c.Field_Api_Name__c'
    – Jeff Kranz
    Mar 25, 2021 at 4:26
  • 1
    thanks, I'll update the answer
    – ytiq
    Mar 25, 2021 at 7:37
  • Thank you, this was really useful.
    – Reaper1883
    Mar 30, 2021 at 19:44

I believe the object you are looking to query is: MetadataComponentDependency

This is most likely what Salesforce uses behind the scenes with the 'Where is this used?' button. I have not tested this, but according to the documentation you should be able to call this using the Tooling API or Bulk API 2.0

Please note, it says that this is currently a feature in Beta so usage may be limited.

Here is a link to the Dependency API/Field Usage chatter group

If you read through the posts, you can probably get a better idea of how to query and what works / doesnt.

Hope that helps and is what you were looking for!

  • Thanks for the reply. You are right, Salesforce does use MetadataComponentDependency in Tooling API for this.
    – Reaper1883
    Mar 30, 2021 at 19:46
  • Note: this doesn't seem to support all metadata types (or even the full set that is returned by "where is this used"). For example, the "Where is this used" shows reports, but this doesn't
    – NSjonas
    Apr 7 at 5:13

You must log in to answer this question.

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