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:
- Go all manual. Review all flows and process builder meticulously. Maybe not so efficient.
- Check which @InvocableMethod‘s live in the Org.
- 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 firstname.lastname@example.org --apiversion 47.0 -t
Spool the output to a file and Bob’s your Uncle!