Sub topic 14
Troubleshooting Failed Deployments
This chapter assumes you can build an outbound change set, upload it, and validate or deploy the inbound change set in the target org. It covers how to read a failure and fix the most common causes.
Where to find the error
Open Setup, then Deployment Status. A failed deployment appears under Failed. Click the change set name to see the details. The page has two lists that matter:
- Component Failures lists metadata that did not deploy, with the problem for each one.
- Test Failures lists Apex tests that failed, with the error message and stack trace.
Deployment is all or nothing. If any component or test fails, Salesforce rolls back the whole change set. Nothing is partly deployed.
Common failures
| Symptom | Likely cause | Fix |
|---|---|---|
| "In field: ... no CustomObject named ... found" | A dependent component is missing from the change set and the target org | Add the missing object, field, or other component and upload again |
| "Invalid cross reference id" or an unknown record type, profile, or user | The target org lacks something the component refers to | Create it in the target org or add it to the change set |
| An Apex test fails in the target org | The test relies on data or settings that differ from the source org | Fix the test so it creates its own data, then redeploy |
| "Average test coverage across all Apex Classes and Triggers is 74%, at least 75% required" | Production runs with too little coverage | Add tests, or include the test classes in the change set |
| "Cannot modify managed object" or a component that cannot be deployed | The component type or managed package item is not supported | Check the limitations from the earlier chapter |
| Version or API mismatch | The source and target orgs run different releases | Wait until both are on the same release |
Missing dependencies
Missing dependencies cause most failures. The View/Add Dependencies button finds many of them, but it does not find everything. It can miss items such as a field referenced inside a formula in a flow, or a record type that a page layout assigns.
To check, compare the change set against the target org:
- Read the error to find the name of the missing component.
- Look for that component in the target org under Setup.
- If it exists, check for a spelling or API name difference. If it does not, add it to the change set.
Failing tests
A test that passes in the sandbox can fail in production. Typical reasons are:
- The test uses
SeeAllData=trueand depends on records that exist only in the sandbox. - A validation rule or required field in production blocks the test's inserts.
- A trigger or flow in the target org, not in the change set, interferes.
Read the stack trace for the class and line number. Then reproduce the failure in the sandbox if you can, or run the test in the target org's Developer Console.
Fix, then validate again
You cannot edit a change set after you upload it. Clone it instead, then add or remove components and upload the new version. Validate the new change set before you deploy it. A validation runs the same checks as a deployment but makes no changes, so you can repeat it safely.
Exercise
A deployment fails with the error "no CustomField named Invoice_c.Status_c found". The change set contains an Apex class that reads this field. What is the most likely cause, and how do you fix it?
Show answer
The field is missing from the change set and does not exist in the target org. Clone the change set, add Invoice_c.Status_c (and its object if needed), upload it, and validate again.
Exercise
A deployment is rolled back after one test fails, even though all components were valid. Why was nothing deployed, and what do you do next?
Show answer
A change set deploys all or nothing, so a single test failure rolls back everything. Open the Test Failures list, read the stack trace, fix the test or its data assumptions, then clone the change set if the contents must change, upload it, and validate again.