Apex Class Dependencies

Q: “How do I determine which Apex Classes each Apex Class depends on?”

A: Tooling API, baby. Here’re the steps I run:

  1. Open Developer Console
  2. Click the “Query Editor” tab of the Console
  3. Activate the “Use Tooling API” checkbox at the bottom of the screen
  4. Paste the following query into the Query Editor:
    SELECT MetadataComponentId, MetadataComponentName, MetadataComponentNamespace, MetadataComponentType, RefMetadataComponentId, RefMetadataComponentName, RefMetadataComponentNamespace, RefMetadataComponentType
    FROM MetadataComponentDependency
    WHERE MetadataComponentType='ApexClass'
    AND RefMetadataComponentType='ApexClass'
  5. Use your favorite table-copying utility (I use Table Capture) to copy the results into your favorite spreadsheet

And here’s the first five rows of what I got:

Random Notes:

  • Querying the Tooling API is always weird. If I run the above query without a WHERE clause, I get thousands of lines back. . . and none of them has a MetadataComponentType or RefMetadataComponentType of ApexClass. Shouldn’t I get all rows? Apparently not, wtf
  • Here’s documentation for the Tooling API’s MetadataComponentDependency object
  • Why didn’t I hide the first three characters of the returned IDs? Because 01p is the prefix of all Apex Classes everywhere, always. Daniel Ballinger’s Fish of Prey list has maintained the list of standard Salesforce ID prefixes for over 11 years!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s