---
schema_version: "1"
id: 782f4dcdde4d4eb70c970dc52e1894083f454fd69ab0259b4d22d08097512801
title: Tooling API Usage
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_tooling/tooling_api_objects_metadatacomponentdependency_tooling_usage.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_metadatacomponentdependency_tooling_usage.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5b47203f09cbf7dd3dd5ff2c5da27f3b89864d234af4dcd2e8b80208290baa0c
description: 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.
---
# Tooling API 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.

This Apex class (YourClass) references a custom field (yourField\_\_c) on the Account object.

public class YourClass {
    public void updateAccount(Account acc, String value) {
        acc.yourField\_\_c = value;
        update(acc);
    }
}

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). 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.

public class ClassA {
    public ClassB newB() {
        return new ClassB();
    }
}

public class ClassB {
    public ClassA newA() {
        return new ClassA();
    }
}

The output for a MetadataComponentDependency query that includes these two classes, each directional relationship (ClassA -> ClassB, and ClassB -> ClassA) are 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.

SELECT MetadataComponentName, MetadataComponentType
    FROM MetadataComponentDependency
    WHERE RefMetadataComponentType = 'ApexClass'

This example shows all references to a field, including references from layouts, Apex code, flows, 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.

SELECT MetadataComponentName, MetadataComponentType
    FROM MetadataComponentDependency
    WHERE RefMetadataComponentId = yourFieldId