Newer Version Available

This content describes an older version of this product. View Latest

MetadataComponentDependency (Pilot)

Represents dependency relationships between the metadata components in your org. Available in API version 43.0 and later.

We provide MetadataComponentDependency to selected customers through a pilot program that requires agreement to specific terms and conditions. To be nominated to participate in the program, contact Salesforce. Pilot programs are subject to change, and we can’t guarantee acceptance. MetadataComponentDependency isn’t generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. We can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features. You can provide feedback and suggestions for MetadataComponentDependency in the Dependency API Pilot group in the Trailblazer Community.

Note

Supported SOAP Calls

query()

Supported REST HTTP Methods

GET

Limitations

SOQL Limitations

SOSL Limitations

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

Fields

Field Details
MetadataComponentId
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The ID of a metadata component that depends on another component.

The component with the ID listed in the output as MetadataComponentId has a reference to the component with its ID listed as RefMetadataComponentId.

MetadataComponentId is a string field that usually contains either an 18-character ID or a standard object name. Use 18-character IDs, not 15-character IDs, in your queries of this field.

MetadataComponentName
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The name of a metadata component that depends on another component. For example, YourClass for an Apex class or yourField (without the __c suffix) for a custom field.

The component with the name listed in the output as MetadataComponentName has a reference to the component with its name listed as RefMetadataComponentName.

MetadataComponentNamespace
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The namespace of a metadata component that depends on another component.

The component with the namespace listed in the output as MetadataComponentNamespace has a reference to the component with its namespace listed as RefMetadataComponentNamespace.

MetadataComponentType
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The type of a metadata component that depends on another component.

The component with the type listed in the output as MetadataComponentType has a reference to the component with its type listed as RefMetadataComponentType.

RefMetadataComponentId
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The ID of a metadata component that another component depends on.

The component with the ID listed in the output as RefMetadataComponentId is referenced by the component with its ID listed as MetadataComponentId.

RefMetadataComponentId is a string field that usually contains either an 18-character ID or a standard object name. Use 18-character IDs, not 15-character IDs, in your queries of this field.

RefMetadataComponentName
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The name of a metadata component that another component depends on. For example, YourClass for an Apex class or yourField (without the __c suffix) for a custom field.

The component with the name listed in the output as RefMetadataComponentName is referenced by the component with its name listed as MetadataComponentName.

RefMetadataComponentNamespace
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The namespace of a metadata component that another component depends on.

The component with the namespace listed in the output as RefMetadataComponentNamespace is referenced by the component with its namespace listed as MetadataComponentNamespace.

RefMetadataComponentType
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The type of a metadata component that another component depends on.

The component with the type listed in the output as RefMetadataComponentType is referenced by the component with its type listed as MetadataComponentType.

Usage

Use SOQL queries to list the relationships between the metadata components in your org. The query results include one row for each relationship. Each relationship is a directional dependency between two metadata components.

For example, this Apex class (YourClass) references a custom field (yourField__c) on the Account object.
1public class YourClass {
2   public void updateAccount(Account acc, String value) {
3      acc.yourField__c = value;
4      update(acc);
5   }
6}

In the output of a MetadataComponentDependency query, the Apex class is represented as a metadata component (the component doing the referencing, represented by MetadataComponent* field values), and the custom field is represented as a referenced metadata component (represented by RefMetadataComponent* field values). Each row in the output shows a directional dependency from one metadata component (such as YourClass) to one of the metadata components that it references (such as yourField).

Each of the two components is represented using four fields.
Id
The ID of this component
Name
The name of this component (for example, YourClass)
Namespace
The namespace this component belongs to (or, if the component isn’t in a package, null)
Type
The type of the component (for example, ApexClass)
In the example of the Apex class referencing a custom field, a row in the output would include something like these values.
  • MetadataComponentId: "01p000000000SOMEID"
  • MetadataComponentName: "YourClass"
  • MetadataComponentNamespace: null
  • MetadataComponentType: "ApexClass"
  • RefMetadataComponentId: "00N000000000SOMEID"
  • RefMetadataComponentName: "yourField"
  • RefMetadataComponentNamespace: null
  • RefMetadataComponentType: "CustomField"
All the MetadataComponent* field values represent the Apex class, and the RefMetadataComponent* field values represent the custom field that the Apex class references.
Each row is a directional dependency, where the metadata component references the referenced metadata component. If two components reference each other, the circular relationship is described as two separate rows. For example, two Apex classes can reference each other.
1public class ClassA {
2   public ClassB newB() {
3      return new ClassB();
4   }
5}
1public class ClassB {
2   public ClassA newA() {
3      return new ClassA();
4   }
5}
In the output for a MetadataComponentDependency query that includes these two classes, each directional relationship (ClassA -> ClassB, and ClassB -> ClassA) would be represented as a separate row.
Row 1 (ClassA -> ClassB):
  • MetadataComponentId: "01p00000000SOMEIDA"
  • MetadataComponentName: "ClassA"
  • MetadataComponentNamespace: null
  • MetadataComponentType: "ApexClass"
  • RefMetadataComponentId: "00N00000000SOMEIDB"
  • RefMetadataComponentName: "ClassB"
  • RefMetadataComponentNamespace: null
  • RefMetadataComponentType: "ApexClass"
Row 2 (ClassB -> "ClassA"):
  • MetadataComponentId: "01p00000000SOMEIDB"
  • MetadataComponentName: "ClassB"
  • MetadataComponentNamespace: null
  • MetadataComponentType: "ApexClass"
  • RefMetadataComponentId: "00N00000000SOMEIDA"
  • RefMetadataComponentName: "ClassA"
  • RefMetadataComponentNamespace: null
  • RefMetadataComponentType: "ApexClass"

In all but the simplest orgs, MetadataComponentDependency queries return a huge number of rows. It can be useful to limit the scope of your requests by type, name, or ID, to help isolate dependencies on specific components.

This SOQL query shows all references to the Apex class YourClass. For example, it shows pages, components, flows, and other classes that YourClass depends on.
1SELECT MetadataComponentName, MetadataComponentType
2    FROM MetadataComponentDependency
3    WHERE RefMetadataComponentType = 'ApexClass'
This example shows all references to a field, including references from layouts, Apex code, flows, reports, and so on. In this example, the code determines the field ID by querying the FieldDefinition object. The query’s output shows all the metadata components that depend on the field with the ID yourFieldId.
1SELECT MetadataComponentName, MetadataComponentType
2    FROM MetadataComponentDependency
3    WHERE RefMetadataComponentId = yourFieldId