Sub topic 8
Running a quick deploy
A quick deploy takes a validation that already passed and saves its changes to the target org without running the Apex tests again. This chapter covers how to run one from the CLI, what happens while it runs, and how to confirm the result.
Prerequisites
This chapter assumes you have:
- Run a validation with
sf project deploy validateand kept its job ID. - Read the previous chapter on eligibility rules: a successful validation, tests that met the coverage requirement, and a validation younger than 10 days.
- Authorized the target org with the Salesforce CLI (
sf) and given it an alias such asprod.
What a quick deploy does
A validation runs the full deployment process, including Apex tests, and then rolls everything back. Salesforce remembers that the validation succeeded. A quick deploy tells Salesforce to reuse that result. Salesforce does these things:
- Looks up the validated deployment by its job ID.
- Checks that the validation is still eligible.
- Saves the validated components to the org.
- Skips the Apex test run.
The tests are the slow part of most production deployments. A validation can take an hour or more, and a quick deploy often finishes in minutes. That is why teams validate days ahead and quick deploy inside the release window.
The command
The command needs the job ID of the validation and the target org:
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prodYou do not pass a manifest, a source directory, or a test level. The validation already fixed all three. If you pass --test-level or --manifest, the command is rejected because those flags do not exist on quick. This also means you cannot change what gets deployed at this point. The quick deploy saves exactly what the validation checked.
Useful flags
| Flag | Purpose |
|---|---|
| `--job-id` (`-i`) | The ID of the validated deployment. It starts with `0Af`. |
| `--use-most-recent` (`-r`) | Uses the job ID of the most recent validation that the CLI stored locally, so you do not copy it. |
| `--target-org` (`-o`) | The org to deploy to. It must be the org the validation ran against. |
| `--wait` (`-w`) | How many minutes the command waits before returning control. |
| `--async` | Returns immediately and lets the deployment continue in the org. |
| `--verbose` | Prints the component table, including the unchanged ones. |
| `--concise` | Prints less output, which suits CI logs. |
| `--json` | Prints machine-readable output. |
Run sf project deploy quick --help to see the flags in your installed CLI version. They have changed between releases.
Waiting, async, and resuming
By default, the CLI waits for the deployment to finish, up to a time limit. If the limit passes first, the command exits with a message that the deployment is still running. This does not cancel the deployment. The org keeps working on it.
You have two options for long runs. The first is to set a longer wait:
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prod \
--wait 30The second is to start it without waiting and then check on it with report:
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prod \
--async
sf project deploy report --job-id 0AfYYYYYYYYYYYYYYY --target-org prodNote that the second command uses a different ID. A quick deploy creates a new deployment record, so it has its own job ID. Read that ID from the output of the quick deploy command. The ID of the validation still refers to the validation, and its status stays at "Succeeded" as a validation. If you report on the wrong ID, you will see the old validation result and may think nothing happened.
If your terminal session ends while the CLI is waiting, the deployment is not lost. Use sf project deploy resume to reattach, or report to read the state.
Capturing the job ID in a script
In a release script, you can pull the IDs out of the JSON output. This example assumes jq is installed:
#!/usr/bin/env bash
set -euo pipefail
ORG=prod
# Days before the release: validate and keep the ID.
VALIDATION_ID=$(sf project deploy validate \
--manifest manifest/package.xml \
--test-level RunLocalTests \
--target-org "$ORG" \
--wait 120 \
--json | jq -r '.result.id')
echo "$VALIDATION_ID" > validation-id.txt
# In the release window: promote the stored validation.
QUICK_ID=$(sf project deploy quick \
--job-id "$(cat validation-id.txt)" \
--target-org "$ORG" \
--wait 30 \
--json | jq -r '.result.id')
echo "Quick deploy job: $QUICK_ID"The two halves normally run in separate jobs, days apart. The only value that connects them is the validation ID, so store it somewhere durable such as the release ticket or a CI artifact. The set -e option stops the script if the command fails. A failed sf command exits with a non-zero code, so the script does not carry on with an empty ID.
What the quick deploy checks
Salesforce does not run Apex tests, but it still checks several things before saving.
- The validation exists and succeeded. A failed or canceled validation has no quick deploy.
- The tests covered the required ground. The validation must have run tests at a level that applies to production. A validation with
NoTestRuncannot be promoted, because there is no test result to reuse. UseRunLocalTestsorRunAllTestsInOrg, orRunSpecifiedTestswhen the specified tests meet the coverage rules for each deployed class and trigger. - The validation is recent. The window is 10 days from the validation's completion, not from when you created the package.
- The target org matches. The ID belongs to one org. You cannot validate against a sandbox and promote that ID to production.
If any check fails, the quick deploy is rejected and nothing is saved. The org stays as it was.
Quick deploy is not a second validation
A quick deploy does not re-run the tests, so it does not catch problems that appeared after the validation. If someone changed the production org between the validation and the quick deploy, for example by editing a field that your Apex depends on, the tests that passed earlier were run against an org that no longer exists. Salesforce may still accept the quick deploy, because the rules above are met.
Two practices reduce this risk:
- Freeze direct production changes, such as admin edits in Setup, between validation and release.
- Re-validate when the gap is long or the org changed. A fresh validation costs time, but it gives you test results for the org as it is today.
Also, a quick deploy can fail for reasons unrelated to tests. Examples include a component that is locked by another deployment in progress, or a metadata dependency that is no longer in the org. In those cases the error message names the component. Fix the cause and retry. If the validation is still within its window and eligible, you can reuse the same ID.
Reading the result
When the command finishes, the CLI prints a summary. Check these parts:
- Status. You want
Succeeded. - Components deployed. Compare the count and names with the manifest. If a component you expected is missing, the validation did not include it.
- Test results. Expect zero tests run, or no test table. That is normal, because the tests ran during validation.
- Deploy ID. Record the ID of the quick deploy in the release ticket next to the validation ID.
To check the result later, run the report command with the quick deploy's ID:
sf project deploy report --job-id 0AfYYYYYYYYYYYYYYY --target-org prodYou can also open Setup > Deployment Status in the org. A quick deploy appears in the Succeeded Deployments list like any other deployment, and the validation appears there too, marked as a validation.
Common errors
| Symptom | Likely cause | What to do |
|---|---|---|
| The job ID is rejected or not found | The ID is from a different org, or has a typo | Check `--target-org` and copy the ID again from the validation output |
| Quick deploy is unavailable | The validation is older than 10 days, ran with `NoTestRun`, or did not succeed | Run a new validation with a test level that meets production rules |
| The command returns before finishing | The `--wait` time passed | Run `report` with the quick deploy's ID, or use `resume` |
| `report` shows an old validation | You used the validation ID instead of the quick deploy ID | Read the new ID from the quick deploy output |
| The quick deploy fails on a component | Another deployment is running, or a dependency changed | Read the component error, fix it, and retry |
| `--use-most-recent` promotes the wrong change | A later validation overwrote the cached ID | Pass `--job-id` explicitly |
A release-window sequence
Here is how a quick deploy fits the end of a release:
- Confirm the stored validation ID, its completion date, and the commit it was run from.
- Confirm nothing has been changed in production directly since then.
- Run
sf project deploy quick --job-id <ID> --target-org prod --wait 30. - Record the new deployment ID.
- Run
sf project deploy reportor check Deployment Status to confirm success. - Do your post-deployment steps, such as data loads or permission assignments.
If step 3 fails, the org is unchanged, so you can investigate without a rollback. That is the main safety property of this approach.
Exercise
A teammate validated a production deployment on Monday and posted the job ID. On Thursday you run sf project deploy quick --job-id <that ID> --target-org prod --async. The command returns at once. How do you find out whether the deployment succeeded, and which ID do you use?
Show answer
Run sf project deploy report against the production org, using the new job ID printed by the quick deploy command, not the validation ID. A quick deploy creates its own deployment record, so reporting on the validation ID only shows the earlier validation result. You can also check Setup > Deployment Status. The Thursday run is still inside the 10-day window, so it stays eligible as long as the validation succeeded and ran tests that meet the production rules.
Exercise
Why does sf project deploy quick have no --test-level or --manifest flag?
Show answer
Both were fixed during the validation. The quick deploy only promotes the exact components that the validation checked, and it reuses that validation's test results, so there is nothing left to choose.