Sub topic 6
Finding and adding dependent components
This chapter assumes you can build an outbound change set and name its components in Setup. It also assumes you know common metadata types such as custom objects, fields, flows and Apex classes. Here you will learn how to find the components your change set needs but does not yet contain.
Why dependencies matter
A component often relies on other components. A Visualforce page may call an Apex class. A flow may read a custom field. A page layout may show fields and related lists.
A change set does not add these supporting components for you. If a dependency is missing from the change set and also missing in the target org, the deployment fails. The error usually names the missing component, but you only see it after you upload and validate.
The View/Add Dependencies button lets you find these gaps before you upload.
Finding dependencies
- In the source org, open Setup and go to Outbound Change Sets.
- Open your change set. The Change Set Components section lists what you have added so far.
- Click View/Add Dependencies.
- Review the list. Each row shows a component name, its type, and the component that needs it.
- Select the components you want and click Add To Change Set.
Repeat this step after each round of additions. A newly added component can bring dependencies of its own.
Which dependencies to add
Not every listed dependency must be added. Whether to add it depends on the target org.
| Situation | Action |
|---|---|
| The component does not exist in the target org | Add it to the change set. |
| The component already exists and is the same | Leave it out. |
| The component exists but you changed it in the source org | Add it, because the change must travel too. |
| The component is a standard object or field | Leave it out. It exists in every org. |
If you leave a component out, confirm it really exists in the target org. A name match is not enough. A field with the same name but a different data type can still cause a failure.
Limits of the dependency check
The dependency list is helpful but not complete. Keep these gaps in mind:
- It lists components that reference each other directly. It may miss indirect references, such as an Apex class that builds a field name from a string.
- It does not include data, such as records that a flow expects to find.
- Some settings, such as profile or permission set access, may need to be added separately.
For this reason, treat the list as a starting point. Validation in the target org is the real test.
Comparing against a manifest
A manifest can help you check your selection. A package.xml file lists metadata by type and name, which is the same kind of list a change set holds.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Invoice__c</members>
<name>CustomObject</name>
</types>
<types>
<members>InvoiceService</members>
<members>InvoiceServiceTest</members>
<name>ApexClass</name>
</types>
<version>61.0</version>
</Package>The Salesforce CLI can retrieve the components named in a manifest from a sandbox. You can then compare what the source org holds with what your change set will contain.
sf project retrieve start --manifest manifest/package.xml --target-org MySandboxCommon mistakes
- Adding an Apex class but not its test class. Tests may be needed for validation.
- Adding a custom field but not the page layout or permission that exposes it.
- Adding a flow but not the custom fields and objects it uses.
- Skipping the dependency check because a similar change set worked before.
Exercise
You add a flow to a change set. View/Add Dependencies lists a custom field, Region_c, that the flow reads. Region_c already exists in the target org with the same data type. Must you add it?
Show answer
No. The field already exists in the target org and matches, so the flow can use it. Adding it is optional. Add it only if you changed it in the source org and need that change to travel.
Exercise
After you add the dependencies listed for a custom object, you click View/Add Dependencies again and see new entries. Why?
Show answer
Each component you add can have dependencies of its own. The check must be repeated until no new dependencies appear.