function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vishal Negandhi 16Vishal Negandhi 16 

Fetching all references to a field in the environment - Tooling/Metadata API

Hello folks, 

Today we were trying to work on a utility that will list out all references to a field. This is intented to help the business to analyze a field before they plan to update/delete it. 

What we are trying to achieve?
- Once the user selects an object and one of its fields, we want to list out all possible components where the selected field is referenced. 

What were we able to achieve, using what?
- We first tried the Standard SOQL approach and queried objects such as ApexClass, ApexComponent, ApexPage and ApexTrigger : this helped us to find out references of a field in the code by scanning their body/markup. 
- We then thought of utilizing the Tooling API that has a SOSL feature, using which we were able to retreive all the codes where the field was referenced. 
Code snippet:
/services/data/v34.0/tooling/search/?q=FIND{BillingCity}

This gives me a list of all code where there is "BillingCity" referred. 

However, none of the approaches has helped us to touch other components such as:
- formula field
- report filters
- workflow field updates

Wanted to understand how do we get around this?
I know this is possible using Tooling API but then if I end up making one http callout for each component then I am going to make a lot of callouts. 
Is there something I am missing here? 
Need some guidance around this. 

Many thanks in advance!
pconpcon
How I would solve this is to query each "sobject" type via the tooling api (ApexTrigger, ApexClass, etc) and get their bodies downloaded locally. You'll have to do the same with the AnalyticsAPI to describe the reports you have to get their filters.  Then you'll have to use the MetadataAPI to get formula fields and workflow field updates.  I would essentially pull down everything in your org to disk and then search through it.  I would not count on the tooling SOSL to return consistant results because of some of the limitations in native SOSL and not knowing how / if they apply to the ToolingAPI.

You may find that pulling down everything via ANT to disk an search through that.
Jon-FreedJon-Freed
Cross-reference / See also:
Warren Rudman 7Warren Rudman 7
These solutions are great in one-off situations.  How can you document this for an entire object (all fields in Accounts, for example)?
Dhanik L SahniDhanik L Sahni
We can use Tooling api object MetadataComponentDependency fot this .Please refer https://salesforcecodex.com/2020/05/find-referenced-metadata-using-salesforce-dependency-api/