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).
- 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).
- MetadataComponentId: "01p000000000SOMEID"
- MetadataComponentName: "YourClass"
- MetadataComponentNamespace: null
- MetadataComponentType: "ApexClass"
- RefMetadataComponentId: "00N000000000SOMEID"
- RefMetadataComponentName: "yourField"
- RefMetadataComponentNamespace: null
- RefMetadataComponentType: "CustomField"
public class ClassA { public ClassB newB() { return new ClassB(); } }
public class ClassB { public ClassA newA() { return new ClassA(); } }
- MetadataComponentId: "01p00000000SOMEIDA"
- MetadataComponentName: "ClassA"
- MetadataComponentNamespace: null
- MetadataComponentType: "ApexClass"
- RefMetadataComponentId: "00N00000000SOMEIDB"
- RefMetadataComponentName: "ClassB"
- RefMetadataComponentNamespace: null
- RefMetadataComponentType: "ApexClass"
- 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.
SELECT MetadataComponentName, MetadataComponentType
FROM MetadataComponentDependency
WHERE RefMetadataComponentType = 'ApexClass'
SELECT MetadataComponentName, MetadataComponentType
FROM MetadataComponentDependency
WHERE RefMetadataComponentId = yourFieldId