We are all quite familiar with dependencies when it comes to implementing a solution. Now, imagine you need to make changes to a solution you’ve implemented, and you’re uncertain about all the different metadata components being referenced, whether in an Apex class or a flow.
Fortunately, luck is on your side. In Winter ’20, Salesforce introduced a highly intriguing feature known as the Dependency API, albeit still in beta. With the Metadata Dependency API, you can query all the referenced metadata within a component. These dependencies are stored as records in MetadataComponentDependency. You can refer to this link to gain a comprehensive understanding of all the fields present in the MetadataComponentDependency object.
How can you construct this query?
You can execute this query directly from your Developer Console using the Query Editor, but you’ll need to enable the ‘Tooling API’ checkbox.
Select MetadataComponentId,MetadataComponentName,RefMetadataComponentName,RefMetadataComponentId from MetadataComponentDependency where MetadataComponentId = '01q0J000000kCzI
Alternatively, you can utilize the Rest API or Salesforce CLI to perform these queries.
Factors to Take Into Account and Constraints:
It’s crucial to acknowledge these factors and restrictions to determine the specific use cases where you can leverage this feature to your benefit.
Firstly, it’s important to note that this feature is currently in BETA. It’s exclusively accessible in Sandboxes at the moment, and you won’t be able to use it in Production environments or Developer editions (Attempting to do so will result in an error message: ‘Dependency API not enabled’). The plan is to make it generally available (GA) in the next release.
Furthermore, there are certain limitations pertaining to the SOQL queries you can execute; you can find more details about these limitations in the provided link.
Hope you had fun reading!
We appreciate your fantastic readership! Don’t forget to subscribe to this blog to receive all the latest updates directly in your inbox.