Untangle Your Dependencies with MetadataComponentDependency Queries (Beta)

Many orgs are cluttered with custom objects and fields that are no longer in use. Use the Tooling API MetadataComponentDependency object to view the dependency relationships between metadata components in your org. This information helps you determine whether components are safe to delete. Finding dependencies among components also helps you break up your metadata into packages. Working with a set of packages rather than with one monolithic org makes it easier to manage change, use a version control system, or use a continuous integration system.

Where: This change applies to Lightning Experience, Salesforce Classic, and all versions of the Salesforce app in Professional, Enterprise, Performance, Unlimited, and Developer editions, sandboxes only.

Note

Note

As a beta feature, MetadataComponentDependency is a preview and isn’t part of the “Services” under your master subscription agreement with Salesforce. Use this feature at your sole discretion, and make your purchase decisions only on the basis of generally available products and features. Salesforce doesn’t guarantee general availability of this feature within any particular time frame or at all, and we can discontinue it at any time. This feature is for evaluation purposes only, not for production use. It’s offered as is and isn’t supported, and Salesforce has no liability for any harm or damage arising out of or in connection with it. All restrictions, Salesforce reservation of rights, obligations concerning the Services, and terms for related Non-Salesforce Applications and Content apply equally to your use of this feature. You can provide feedback and suggestions for MetadataComponentDependency in the Dependency API Pilot group in the Trailblazer Community.

How: Use SOQL queries to get the relationships between the metadata components in your org. The query results include one row for each relationship. You can get up to 2,000 records per query. Keep your queries specific enough to return accurate results within this record count.

{
  "size" : 132,
  "totalSize" : 132,
  "done" : true,
  "queryLocator" : null,
  "entityTypeName" : "MetadataComponentDependency",
  "records" : [ {
    "attributes" : {
      "type" : "MetadataComponentDependency",
      "url" : "/services/data/v47.0/tooling/sobjects/MetadataComponentDependency/000000000000000AAA"
    },
    "RefMetadataComponentId" : "00NXXXXXXXXXXXXXXX",
    "RefMetadataComponentName" : "acctTime",
    "MetadataComponentName" : "acctTimeReport",
    "MetadataComponentType" : "Report"
  },  {
    "attributes" : {
      "type" : "MetadataComponentDependency",
      "url" : "/services/data/v47.0/tooling/sobjects/MetadataComponentDependency/000000000000000AAA"
    },
    "RefMetadataComponentId" : "00XXXXXXXXXXXXXXXX",
    "RefMetadataComponentName" : "acctTime",
    "MetadataComponentName" : "formulaTime",
    "MetadataComponentType" : "CustomField"
  },...

The following queries are not supported.

  • SOQL ORDER BY clause
  • SOQL SELECT clause—count() function
  • SOQL queryMore()
  • SOQL WHERE clause—Any type of filter with MetadataComponentName
  • SOQL WHERE clause—Any type of filter with RefMetadataComponentName
  • SOQL WHERE clause—Contains operators other than =, !=, AND, or OR
  • SOQL WHERE clause—Filter by (RefMetadataComponentType = 'StandardEntity')
  • SOQL WHERE clause—Use of the LIKE operator with either the MetadataComponentType field or RefMetadataComponentType field
  • SOQL OFFSET clause

For more information, see MetadataComponentDependency.