Sub topic 7
When Quick Deploy Is Available
This chapter assumes you can run sf project deploy validate and read its output. It also assumes you know the test levels and the 75% coverage rule. Here you learn exactly which validations can be promoted with quick deploy, which events make them ineligible, and how to check eligibility before a release window starts.
What quick deploy does
A validation-only deployment runs the full deployment pipeline against the target org: component checks, compilation, and Apex tests. It then discards the result instead of saving it. Quick deploy reuses that work. When you quick deploy a validation, Salesforce skips the Apex tests and saves the components that were validated.
The time saving is the point. A production deployment with RunLocalTests in a large org can run for an hour or more, and a quick deploy of the same package often finishes in minutes. Quick deploy is not a separate deployment type with its own package. It is an action on an existing validation, identified by the validation's job ID (the value that starts with 0Af).
The block above is only a placeholder for layout. The real diagram is later in this chapter.
The eligibility rules
A validation can be quick deployed only when all of these conditions hold.
| Condition | What it means in practice |
|---|---|
| The validation succeeded | The job status is `Succeeded`. A validation that failed or was canceled has nothing to promote. |
| It ran against the same org | The validation must have been run against the org where you quick deploy. You cannot validate in one org and promote in another. |
| Tests ran as part of the validation | The validation used a test level that runs Apex tests. A validation with `NoTestRun` has no passing test results to reuse. |
| All tests passed | Every test that ran in the validation passed. |
| Coverage requirements were met | The coverage check for that test level passed (see below). |
| It is recent | The validation completed within the last 10 days. |
| The package is unchanged | You promote exactly what was validated. You cannot add, remove, or edit components at quick deploy time. |
The 10-day limit is measured from when the validation finished, not from when it started. Plan release dates with that window in mind. A validation done two weeks before a release has expired by the release date, and you must validate again.
Coverage depends on the test level
The coverage condition differs by test level, which is why the level you chose in the validation matters later.
- With
RunLocalTestsorRunAllTestsInOrg, the org-wide coverage must be at least 75%, and every Apex trigger being deployed must have some coverage. - With
RunSpecifiedTests, each Apex class and trigger in the deployment must have at least 75% coverage from the specified tests. The org-wide figure is not what is checked.
This difference catches teams out. A package of three small classes can pass RunSpecifiedTests validation only if each class is individually covered at 75% or more by the tests you named. Naming tests that cover two of the three classes fails the validation, and so there is nothing to quick deploy.
What invalidates a validation
A validation can be eligible when you check it in the morning and ineligible by afternoon. Watch for these causes.
- Time. The 10-day window passes.
- A different package. Any change to the source, even a comment in a class, means the validated job no longer matches what you want to ship. You must run a new validation. The old job ID is still valid for the old package.
- Changes in the target org. If someone else deploys changes to the target org after your validation, the validated state may no longer hold. A new Apex class or a changed trigger can alter test results and coverage. Treat any intervening deployment to production as a reason to re-check eligibility, and re-validate if quick deploy is refused.
- A failed or canceled job. Only
Succeededvalidations qualify. A job that isCanceled,Failed, or stillInProgresscannot be promoted.
Salesforce decides eligibility on the server when you ask for the quick deploy. The CLI does not predict it. For that reason, the practical habit is to confirm the state of the validation before the window, not to rely on your memory of a green result.
Checking a validation before the window
Start by confirming the job ID and status with sf project deploy report. This is the same command you used earlier to read results.
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodLook at three things in the output:
- The status is
Succeeded. - The test summary shows all tests passed, with no failures.
- The completion time is within the last 10 days.
If the output shows Failed, the validation cannot be quick deployed, and the failures section tells you why. The troubleshooting chapter covers reading those failures in detail.
You can also check in Setup. Open Deployment Status and look under Succeeded Validations. The page lists recent validations that can still be promoted, and each row has a Quick Deploy button. A validation that is missing from this list is a strong sign it is ineligible. Either it has expired, or it did not meet the test and coverage conditions.
The decision flow
The diagram shows the checks in the order that is cheapest to verify.
Every "No" path ends in the same place: a new validation. Quick deploy has no repair mode. If the validation is not eligible, you cannot adjust a setting to make it so.
Running the promotion
When the checks pass, the command is short. It references the job ID and the org, and nothing else describes the package or tests.
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prodThis command does not accept --manifest, --source-dir, or --test-level. The package and the test results come from the validation. The command returns a new deployment, with its own job ID. You use that new ID to track the quick deploy, while the validation's ID stays attached to the validation.
If you want the CLI to return immediately, add --async and check progress later with sf project deploy report using the new job ID. If you omit the flag, the CLI waits for the deployment to finish, up to its default wait time.
For the full run-through, including what the output looks like, see the next chapter on running a quick deploy.
How the original manifest fits in
The package manifest you validated is the contract. A minimal one looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>AccountService</members>
<members>AccountServiceTest</members>
<name>ApexClass</name>
</types>
<version>60.0</version>
</Package>After the validation succeeds, keep this manifest and the source it points to under version control, tagged with the job ID. If the release is approved and the validation expires, you can re-run the same validation from the same commit and get the same package. Quick deploy requires that you promote the validated job. Source control makes re-validation reproducible when you have to do it.
Common mistakes
- Validating with
NoTestRun"to save time", then expecting quick deploy. There are no test results to reuse, so the validation is ineligible. Production deployments that include Apex also require tests, so this validation does not represent the real deployment anyway. - Using
RunSpecifiedTestswith incomplete coverage. The per-class 75% rule fails the validation, so no quick deploy is possible. - Losing the job ID. The ID is printed when you start the validation. If you did not save it, you can find it again with the Deployment Status page in Setup, which lists recent validations.
- Validating too early. A validation done 11 days before the window has expired by the window, so the time you spent is gone.
- Editing the package after validation. Any change means a new validation, even if the edit looks trivial.
- Ignoring other deployments to production. Another team's deployment between your validation and your window can leave you with a validation that is refused. Coordinate release calendars.
Exercise
A team validated a package against production with RunSpecifiedTests, naming one test class. The package contains an Apex class OrderService and an Apex trigger OrderTrigger. The named test covers OrderService at 90% and OrderTrigger at 60%. Will the validation be eligible for quick deploy, and why? What are two other reasons a validation could stop being eligible even if it succeeded?
Show answer
No. With RunSpecifiedTests, each class and trigger in the deployment needs at least 75% coverage. OrderTrigger has 60%, so the validation fails and there is nothing to quick deploy. They need to add tests, then re-validate. Other reasons a succeeded validation can become ineligible: more than 10 days have passed since it completed, or the package changed after validation (or the target org changed in a way that affects the validated state, such as another deployment). Either case requires a new validation.
Exercise
Why does sf project deploy quick take only a job ID and a target org, and not a manifest or a test level?
Show answer
Quick deploy promotes a specific earlier validation. The package contents, the test level, and the passing test results all come from that validation, so none of them can be changed at promotion time. Changing any of them means running a new validation.