Sub topic 11
Deploying and Reading Deployment Status
This chapter assumes you can work in Setup and know the difference between sandboxes and production. It also assumes the outbound change set has been uploaded and a deployment connection exists. Your user needs the Deploy Change Sets permission in the target org. Here you start the deployment from the inbound change set, watch it run, and read the result.
Where a deployment starts
Open Setup in the target org and search for Inbound Change Sets. The page has two lists:
- Change Sets Awaiting Deployment holds uploaded change sets that have not been deployed.
- Change Sets holds the history of deployments that already ran.
Click the change set name to see its component list. Check it against what the sender intended. Then choose one of two actions:
- Validate runs the deployment as a rehearsal and saves nothing to the org.
- Deploy applies the components for real.
You normally validate first, as the previous chapter explained. Deploying directly is fine for a small, low-risk change set going to a sandbox. For production, a validated change set is the safer path.
Choosing test options at deploy time
When the change set contains Apex classes or triggers, the deploy dialog offers a test level. The options depend on the target org.
| Target org | Default behavior | Other options |
|---|---|---|
| Sandbox | No tests run | Run local tests, run all tests, run specified tests |
| Production | Local tests run if the change set has Apex components; none run otherwise | Run local tests, run all tests, run specified tests |
Local tests are all tests except those that come from managed packages. A production deployment that includes Apex must reach at least 75% overall code coverage, and every trigger needs some coverage. Tests that fail will fail the deployment.
The deployment is all or nothing
A deployment is atomic. If any component fails, Salesforce rolls back everything the deployment changed. You will not find half a change set in the org, and you do not need to clean up after a failure. The opposite is also true: a successful deployment has no built-in undo. To reverse it, you must deploy the earlier versions of the components, or delete the new ones by hand.
Following progress on the Deployment Status page
After you click Deploy, Salesforce queues the deployment. Open Setup and search for Deployment Status to follow it. The page groups deployments into these sections:
- Pending Deployments: waiting to start.
- Deployments In Progress: currently running, with a progress bar and, when tests run, a count of tests completed.
- Succeeded Deployments and Failed Deployments: the recent history.
- Canceled Deployments: stopped by a user before they finished.
The page offers Cancel while a deployment runs. Cancel does not stop it instantly. A component that is already being saved may finish first, and then the rollback applies. Wait for the status to change to Canceled before you assume the org is untouched.
Salesforce also sends an email to the user who started the deployment when it finishes. You do not need to keep the page open.
When a deployment stays pending
A deployment can wait in the queue if another deployment is running in the same org. Apex jobs can also hold it back. If Apex classes in your change set are used by scheduled or queued jobs, Salesforce may refuse to deploy them while those jobs run. Setup has a Deployment Settings page with an option to allow deployments while Apex jobs are pending or in progress. Turn it on only when you understand what those jobs do. A job that runs against a half-updated class is a real risk.
Reading the deployment details
Click a deployment's name or View Details to open its result page. A failed deployment shows a red banner with these sections:
- Status and counts. The page shows the total number of components deployed and how many had errors, for example
Components: 14 of 15 deployed, 1 error. - Component Failures. Each row lists the component name, its type, and the problem. This is where you read messages such as a missing dependency or a field that cannot be changed.
- Test Failures. Each row lists the test class and method, the message, and the stack trace.
- Code Coverage Warnings. These list classes or triggers below the required coverage, and the overall percentage if it is under 75%.
- Run Test Results and Deployment Results. These give the full list of tests run and components processed, including the ones that succeeded.
Read the sections in order. A component failure usually explains the rest. If a class fails to compile, its tests fail, and the coverage warnings follow from that. Fix the first error and many of the later ones disappear.
Deploying a validated change set quickly
After a successful validation, Salesforce can reuse that result. In the inbound change set list, a recently validated change set can be deployed without running the tests a second time. This is called a quick deploy. These conditions apply:
- The validation must have run the tests, and they must have passed.
- The validation must have succeeded within the last 10 days.
- Some changes in the org after validation can cancel the option, so check that the Deploy button still offers the shortcut.
For production deployments with many tests, a quick deploy is the main way to shorten a release window. You validate during the day, then deploy in minutes in the evening.
Verifying the result
A Succeeded status says the components were saved. It does not show they behave correctly. Do three checks:
- Open the change set's component list on the result page and confirm the count matches what you expected.
- Open a couple of the components in Setup. For example, check that a new field is on the object and its field-level security is what you intended.
- Run a short manual test of the feature, such as creating a record that uses the new field.
You can also compare against the source with the Salesforce CLI. Retrieve the same components from the target org, using the manifest that lists them, and compare them with the files from the sandbox.
<?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>sf project retrieve start --manifest manifest/package.xml --target-org MyProductionHere MyProduction is the alias you gave the production org when you logged in with the CLI. A file comparison tool, or Git if the project is under version control, shows any difference between the two sets of files.
Common outcomes and what to do
| What you see | Likely cause | First action |
|---|---|---|
| Stays in Pending | Another deployment or an Apex job is running | Wait, or check Deployment Settings for Apex jobs |
| Fails with a component error naming a missing item | A dependency was not included | Add it in the source org and upload a new change set |
| Fails with test failures | A test depends on data or on settings that differ in the target | Read the stack trace, fix the test or the setup |
| Fails on coverage | Coverage below 75% or a trigger with no coverage | Add or fix tests in the source org and upload again |
| Succeeded but behavior is wrong | A manual step was not done | Go to the post-deployment checklist |
A change set cannot be edited after upload. Every fix means going back to the source org, changing the outbound change set (or cloning it), and uploading again. That is why validating first saves time.
Exercise
You validated a change set in production on Monday with the default test level. It contained Apex classes, and the tests passed. On Friday of the same week you deploy it, and the dialog does not offer a quick deploy. Name two reasons that could explain this, and say what you would do next.
Show answer
Two possible reasons: the validation did not count as a full test run that qualifies (for example, it ran no tests), or the org changed after the validation so the saved result no longer applies. Both are consistent with a validation made within 10 days. Next, run the validation again with the test level you want, wait for it to succeed, and then deploy. If you must deploy now, deploy with the normal test run and watch the Deployment Status page for failures.
Exercise
A deployment shows "Failed" with 1 component error and 6 test failures. Which section do you read first, and why? Is any part of the change set now in the org?
Show answer
Read the Component Failures section first. A component that fails to compile or save often causes the test failures and coverage warnings that come after it. Nothing from the change set is in the org, because a failed deployment is rolled back as a whole.