Sub topic 8
Running a quick deploy
This chapter assumes you can run sf commands against an authorized production org. It also assumes you have already completed a successful validation and saved its job ID. A quick deploy promotes that validated deployment. It does not run the Apex tests again, so it usually finishes much faster than a full deployment.
What a quick deploy does
A validation runs your tests and checks the metadata, but it saves nothing. A quick deploy takes the result of that validation and commits the same metadata to the org. Salesforce reuses the earlier test results instead of repeating them.
You identify the validation by its job ID. This is the ID that starts with 0Af. You do not pass a manifest or a test level, because both come from the validation.
Before you run it
Check these points first:
- The validation succeeded and ran the tests that the org required.
- The validation was run against the same org you are deploying to.
- The validation is recent. A validation stays eligible for quick deploy for 10 days after it completes.
- Nobody has changed the affected components in a way that conflicts with the validated package since the validation ran.
If you no longer have the job ID, look up the validation first. You can check its state with the report command.
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodLook for a status of Succeeded. A validation that failed, or one that was canceled, cannot be promoted.
Running the quick deploy
Pass the job ID and the target org to the quick command.
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prodThe command starts a new deployment. It prints a deploy ID, which is a different job ID from the one you validated. Keep this new ID, because you use it to follow the deployment.
By default the command waits for the deployment to finish. If you want it to return immediately, add --async. You can then check progress later.
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prod \
--async
sf project deploy report --use-most-recent --target-org prodThe --use-most-recent flag reports on the last deployment started from your project. If several people deploy at once, pass the explicit job ID instead.
What happens inside the org
The org still locks the components while it saves them, so a quick deploy can fail if another deployment is running at the same moment. It also does not re-check coverage by running tests, which is why the validation must have covered the right tests.
Common errors
| Symptom | Likely cause | What to do |
|---|---|---|
| The org reports that the validation is not eligible | The 10-day window passed, or the validation did not run the required tests | Run a new validation |
| The job ID is not found | You used the ID of a different org, or you used an ID that is not a validation | Confirm the ID and the `--target-org` value |
| The quick deploy fails on a lock or conflict | Another deployment or a package change is in progress | Wait, then retry the command |
| You only validated with `NoTestRun` | Production requires tests, so the validation cannot be promoted | Validate again with `RunLocalTests` or another valid level |
If quick deploy is not available, the fix is almost always to validate again. Plan for this in your release schedule so a failed promotion does not leave you without time to rerun the tests.
Verifying the result
After the deployment finishes, confirm it with the report command, using the new deploy ID.
sf project deploy report --job-id 0AfYYYYYYYYYYYYYYY --target-org prodCheck that the status is Succeeded and that the component counts match what you validated. In Setup, you can also open Deployment Status and look under Succeeded Deployments.
Exercise
You validated a package on Monday with RunLocalTests and it succeeded. On Wednesday you fixed a typo in one Apex class and want to release. Can you quick deploy the Monday job ID? Explain why or why not.
Show answer
No. A quick deploy deploys exactly what was validated, so it would not include the typo fix. You must run a new validation with the changed class, confirm it succeeds, and then quick deploy the new job ID.
Exercise
Write the command that starts a quick deploy for job ID 0AfXXXXXXXXXXXXXXX against the org alias prod and returns immediately without waiting.
Show answer
sf project deploy quick --job-id 0AfXXXXXXXXXXXXXXX --target-org prod --async