Hands-on With the Salesforce Metadata Dependency API

I needed to quickly analyze the potential impact of one of the Salesforce Critical Updates, which is going to auto-activate per December 2nd 2019:

Improve Security by Requiring User Access to Apex Classes Invoked by Flow (Critical Update)

Different options of course:

  1. Go all manual. Review all flows and process builder meticulously. Maybe not so efficient.
  2. Check which @InvocableMethod‘s live in the Org.
  3. Use the Dependency API!

That latter option (of course) I deemed would be best. The Metadata Dependency API has become GA with the Winter ’20 release. The timing is perfect (sometimes). Wanna learnĀ moar about it? Check this blog post.

So what to do? Ideally I wanted to get a list of all Flows having a reference to any Invocable method. The nice thing is, the Dependency API is accessible through SOQL using the Tooling API. That comes in handy. Of course there are limitations as to how to query. No groupings, maximum 2,000 results, and limited WHERE clauses. That said, the following query seemed to work nicely from the Developer Console.

SELECT MetadataComponentName, MetadataComponentType, RefMetadataComponentName 
FROM MetadataComponentDependency 
WHERE RefMetadataComponentType = 'ApexClass' AND MetadataComponentType = 'Flow'

But since several classes where used in many different Flows, and also Inactive flows are considered by the Dependency API I needed to have the output in a comma-separated form to quickly run a pivot table.

SFDX CLI to the rescue!

The nice thing about the SFDX CLI is that it’s being improved on a hyper-frequent basis. The CLI can run SOQL against the Tooling API and can format the output as CSV. What more do we need?

sfdx force:data:soql:query 
-q "SELECT MetadataComponentName, MetadataComponentType, RefMetadataComponentName 
FROM MetadataComponentDependency 
WHERE RefMetadataComponentType = 'ApexClass' 
AND MetadataComponentType = 'Flow'"  
--resultformat csv 
-u jburgers@xxxxxxxx.com.uat 
--apiversion 47.0 -t

Spool the output to a file and Bob’s your Uncle!

About the Author Jeroen Burgers

Salesforce Technical Architect | Platform-Addict & Fan | Working & Living in the Netherlands | 's-Hertogenbosch | Kim, Jens & Kris | 4x+ Rowing | No Soliciting - Please

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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

%d bloggers like this: