0

I'm trying to use the Tooling APi to get the 'Where is this used?' data for all Contact custom fields, but I dont know how to filter on only custom fields for the Contact object, I have this so far:

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

Due to the large number of records and it seems there is a limit of 2,000 records returned, I cannot find the records for just the custom Contact fields or return in the dataset the object the custom field relates to.

Can anyone help please?

1 Answer 1

0

First, you should query ids for Contact custom fields in Tooling API:

SELECT Id FROM CustomField WHERE TableEnumOrId = 'Contact'

When you retrieve your ids, parse them with any tool (for example, with Apex) into a String:

System.debug('\'' + String.join(contactFieldsIds, '\', \'') + '\'');

And now you can query MetadataComponentDependency with condition on RefMetadataComponentId like (pass your ids String to the query, I've added three ids for an example):

SELECT MetadataComponentType, MetadataComponentName, RefMetadataComponentName, RefMetadataComponentId, RefMetadataComponentType 
FROM MetadataComponentDependency 
WHERE RefMetadataComponentId IN ('00N1I00000EWROuUAP', '00N1I00000OAoiEUAT', '00N1I00000OApDtUAL') 
AND RefMetadataComponentType = 'CustomField'  
ORDER By RefMetadataComponentName
4
  • Thank you so much Mariia! Shame it only returns a max of 2k records, I suppose I will need to filter on MetadataComponentType - unless there is a better way to get more than 2k records?
    – Rich
    Feb 22, 2022 at 9:23
  • @Rich Here is an answer from documentation: If the query result is too large, it’s broken up into batches. The response contains the first batch of results and a query identifier. The identifier can be used in a request to retrieve the next batch. developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/… Just get the next records url from response and get next batch. Feb 22, 2022 at 9:39
  • When a SOQL query is executed, up to 2,000 records can be returned at a time in a synchronous request. If the number of results exceeds this limit, the response contains only the first set of results and a query identifier, contained in the response’snextRecordsUrl field. The identifier can be used in another request to retrieve the next batch of records. Feb 22, 2022 at 9:43
  • Thank you Mariia, thats really helpful - I'll probably have to get some help from a Dev for that, but really useful to know, thanks again.
    – Rich
    Feb 26, 2022 at 10:26

You must log in to answer this question.

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