Sub topic 6
Finding and adding dependent components
This chapter assumes you can build a basic outbound change set, know how sandboxes and production relate, and recognize common metadata types such as custom objects, fields, flows, and Apex classes. Here you learn how dependencies work in a change set and how to add them before you upload.
What a dependency is
A component is dependent when it needs another component to exist in the target org. A validation rule on Invoice__c needs the object and any fields it references. An Apex class needs the objects, fields, and other classes it calls. A flow needs the fields it reads and writes. A page layout needs the fields and related lists it places.
The target org must contain every required component by the time the deployment runs. Each one must either already be there or be in the change set. If a required component is in neither place, the deployment fails.
A change set does not add dependencies for you. You choose the components, and Salesforce offers help to find what you missed. You decide what goes in.
Why dependencies are easy to miss
Several things hide dependencies.
- Indirect references. A class may call a second class that uses a custom field. Only the second class names the field.
- Components already in the target. A dependency that was deployed earlier is fine. You cannot see this from the source org, so check the target when unsure.
- Components that look unrelated. A record type needs its picklist values. A permission set needs the objects and fields it grants access to.
- Different names or API versions. A component with the same label in both orgs may have a different API name.
The View/Add Dependencies tool
The change set detail page has a View/Add Dependencies button in the Change Set Components section. It scans the components already in the change set and lists the components they need that are not yet included.
Follow these steps.
- In the source org, open Setup, search for Outbound Change Sets, and open your change set.
- In Change Set Components, click View/Add Dependencies.
- Review the list. Each row shows the component name, its type, and the component that requires it.
- Select the rows you want, or select all.
- Click Add To Change Set.
Run the tool again after adding. The newly added components can have dependencies of their own, and the tool does not always follow the whole chain in one pass. Repeat until the list is empty.
Reading the dependency list
The tool describes a relationship, so read it before you click Add. Not every listed component belongs in the change set.
| Situation | What to do |
|---|---|
| The dependency is new in the sandbox | Add it. It does not exist in production. |
| The dependency already exists in production and is unchanged | Skip it. Adding it only adds risk. |
| The dependency exists in production but you changed it in the sandbox | Add it, and check what else the change affects. |
| The dependency is a managed package component | Install or upgrade the package in the target first. |
Adding an unchanged component is not harmless. Deploying it overwrites the version in the target. If someone changed that component in production directly, your deployment replaces their work.
Dependencies the tool does not find
The tool relies on the references Salesforce can detect. It misses some, so treat its output as a starting point.
- Dynamic references. Apex that builds a field name from a string, such as
Schema.describeSObjects, or a SOQL query built at runtime, has no static reference to detect. - Hard-coded IDs and names. A flow or class that refers to a record type or queue by ID or developer name may not report it.
- Related setup data. A queue, a public group, or a role is not metadata you can always include, and it may need to exist in the target before deployment.
- Access settings. Field-level security and object permissions live in profiles and permission sets. A new field is deployed without access for anyone unless you also add the relevant permission set or profile.
For these cases, read the code and configuration yourself. The retrieve command below helps you compare. It pulls the same components a manifest names from a sandbox, so you can inspect the files and search them for references.
<?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>This package.xml manifest lists metadata by type and name. A change set holds the same kind of component list. Retrieve those components with the Salesforce CLI.
sf project retrieve start --manifest manifest/package.xml --target-org MySandboxAfter the retrieve finishes, search the downloaded files for custom field names, class names, and record type names. Anything you find that is not in your change set deserves a check.
Profiles and permission sets
Profiles are a common source of confusion. When you add a profile to a change set, only the settings for the other components in that change set are deployed with it. Settings for components that are not included are not carried over. This lets you grant access to a new field without replacing the whole profile.
Permission sets work the same way for this purpose, and they are usually the cleaner choice. They are separate from the profile, so you can add one without touching how existing users are set up.
If a new field is deployed but users cannot see it, the missing piece is usually field-level security. Add the profile or permission set to the change set and deploy again.
A worked example
You built an Invoice__c object in a sandbox. It has a custom field Total_Amount__c, a validation rule, a page layout, an Apex class InvoiceService, and its test class InvoiceServiceTest. You add the object, the class, and the test class to your change set.
You click View/Add Dependencies. The tool lists the following.
Invoice__c.Total_Amount__c, required byInvoiceService.Invoice__c.Status__c, required byInvoiceService.Customer_Tier__con Account, required byInvoiceService.
You check production. Total_Amount__c and Status__c exist only in the sandbox, so you add both. Customer_Tier__c already exists in production and has not changed, so you skip it.
You run the tool again. A new row appears for Invoice_Status (a global picklist value set) required by Status__c. You add it and run the tool a third time. The list is empty.
The page layout and validation rule never appeared. Nothing in the change set referenced them, so the tool had no reason to list them. They are part of the feature, and you must add them manually. A final check against your list of what the feature includes catches this.
Common mistakes
- Adding everything. Selecting every dependency without checking the target creates unnecessary overwrites.
- Running the tool once. The first pass may not return every level of the chain.
- Forgetting access. Fields exist after deployment, but nobody can use them.
- Forgetting the test class. Production deployments run tests, and a class without coverage can block the deployment.
- Assuming the sandbox and production match. A sandbox refreshed months ago may differ from production in ways that make a dependency appear present when it is not.
Summary of the process
Exercise
You added the Apex class InvoiceService to a change set. View/Add Dependencies lists the custom field Customer_Tier__c on Account. It already exists in production and is unchanged. Should you add it? Give one reason for your answer, and name one kind of dependency the tool could still miss.
Show answer
No. Adding it would overwrite the production version with the sandbox version and could discard changes made directly in production, with no benefit since the field already exists. The tool can miss dynamic references such as Apex that builds a field name from a string, hard-coded IDs or names, and access settings such as field-level security that live in profiles or permission sets.
Exercise
After deployment, a new field exists in production but no user can see it. The change set contained the field and its class. What was most likely left out, and how do you fix it?
Show answer
Field-level security was left out, because it is stored in profiles or permission sets, which the dependency tool does not add on its own. Create a change set (or clone the previous one) that adds the relevant permission set or profile, upload it, and deploy it.