Is there an easy way to discover where a custom field is referenced in Apex code without attempting to delete it?

E.g. an org with a large code base has objects A, B, and C that all contain a custom field named 'my_custom_field__c'. Is there an easy way to discover references to C.my_custom_field__c?

You can find references to a field (not including inside strings like below) by attempting to delete the field. Does Salesforce expose this functionality some other way?

// Not listed as a reference by Salesforce's delete tool
String s = 'select my_custom_field__c from C'; 
  • You can try to edit the API Name instead of deleting the field. Otherwise we need to know which IDE you prefer.
    – Adrian Larson
    Feb 3 '16 at 17:17
  • If achieving it programmatically is not a compulsion then you can use few chrome extensions.
    – Jarvis
    Feb 3 '16 at 18:27
  • @AdrianLarson I usually use SublimeText with the MavensMate plugin. I've tried doing text searches for the field, but that returns A.my_custom_field__c, B.my_custom_field__c, and C.my_custom_field__c - not just C.my_custom_field__c.
    – bafuda
    Feb 4 '16 at 21:43

A really good news!

Salesforce is going to provide out of the box feature to show the references of custom field after winter' 19. https://releasenotes.docs.salesforce.com/en-us/winter19/release-notes/rn_forcecom_fields_where.htm

enter image description here

Also, if you want to access it programmatically then you can use Tooling api to by making just a query on MetadataComponentDependency. However, this is pilot and need to ask Salesforce enable it. Here is more detail: https://developer.salesforce.com/docs/atlas.en-us.214.0.api_tooling.meta/api_tooling/tooling_api_objects_metadatacomponentdependency.htm

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.