Sub topic 12
Planning Validation Around a Release Window
This chapter assumes you can run a validation with sf project deploy validate and a quick deploy with sf project deploy quick. It also assumes you know the 75% code coverage rule for production and the 10-day limit on quick deploy eligibility, both covered earlier in this tutorial. Here you combine those pieces into a release plan. The plan moves the slow part of a production deployment, running Apex tests, out of the release window and leaves only a short promotion step inside it.
Why split a release into two phases
A production deployment that runs all local Apex tests can take from minutes to several hours, depending on how many tests the org has. While it runs, the org is busy. Deployments can lock metadata, and a long deployment is hard to fit into a window where users expect a short interruption.
A validation runs the same checks, including tests, but saves nothing. A quick deploy then promotes that validated deployment without running the tests again. The release splits into two phases:
- Validation phase. This happens before the window, at a time that suits the team. It is slow, and nothing in the org changes.
- Promotion phase. This happens inside the window. It is fast, and it is the only phase that changes the org.
The result is that the long-running risk (failing tests, missing coverage, broken dependencies) shows up days before users are affected. The window is spent on a step that is expected to succeed.
The timeline at a glance
The diagram shows the usual order of events and the point where you fall back to a full deployment.
Deciding when to validate
Quick deploy only works for a validation that succeeded within the last 10 days. Schedule the validation inside that period, but not so late that you have no time to react to a failure.
A workable rule is to validate one to three business days before the window. That leaves room for one or two fix-and-revalidate cycles, and it stays well inside the 10-day limit even if the window slips by a day or two.
Three things decide whether an earlier validation is still the right one:
- Content. The validated deployment is a fixed snapshot of the components you sent. If anyone merges another change after the validation, that change is not in the validated deployment. You must validate again, because quick deploy promotes exactly what was validated and nothing else.
- Target org state. Validation checks your components against the target org as it was at that moment. If another deployment, a manual change in Setup, or a package upgrade alters the org afterward, the result may no longer reflect reality. Treat any production change between validation and release as a reason to check eligibility and consider revalidating.
- Time. Note the date of the successful validation. If the window moves past day 10, revalidate.
Preparing the validation
Use the same manifest and test level you intend for the release. A validation run with different inputs from the release is not a rehearsal of the release. The manifest from earlier in this tutorial is a good base:
<?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>Run the validation against production with RunLocalTests:
sf project deploy validate \
--manifest manifest/package.xml \
--test-level RunLocalTests \
--target-org prodDo not use NoTestRun for a validation you plan to promote. A validation that skips tests cannot give you a deployment that qualifies for quick deploy, because the point of quick deploy is that the tests already ran and passed.
Capturing the job ID automatically
The quick deploy step needs the job ID, which starts with 0Af. Relying on someone to copy it from a terminal is a common cause of delay on release day. A small script can run the validation and store the ID in a file that the release runbook points to.
This script assumes jq is installed and that prod is an authorized org alias.
#!/usr/bin/env bash
set -euo pipefail
ORG="prod"
OUT="validation-result.json"
if ! sf project deploy validate \
--manifest manifest/package.xml \
--test-level RunLocalTests \
--target-org "$ORG" \
--wait 240 \
--json > "$OUT"; then
echo "Validation failed. See $OUT for details." >&2
exit 1
fi
JOB_ID=$(jq -r '.result.id' "$OUT")
echo "$JOB_ID" > validated-job-id.txt
echo "Validated. Job ID: $JOB_ID"
echo "Validated at: $(date -u +%Y-%m-%dT%H:%M:%SZ)"The script stores two things: the JSON output, which has the full test and component results, and the job ID by itself. Record the date as well. Anyone reading the runbook can then see when the 10-day period ends.
If you cannot keep a terminal open, you can look up a job later with the report command:
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodThe report shows the status, the component results, and the test results, so you can confirm a validation succeeded before the window.
Running the promotion inside the window
When the window opens, the promotion needs only the job ID:
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prodA quick deploy does not run the Apex tests again, so it normally finishes much faster than a full deployment. It still takes time to save components, and it can still fail if something in the org has changed in a way that conflicts with the deployment. Reserve time in the window for that outcome. Do not plan on the quick deploy taking seconds.
After it completes, check the result with the report command and confirm the changes in the org. A successful status means the components were saved. It does not replace the post-release checks your team already does, such as a smoke test of the changed feature.
A runbook you can reuse
A short table of who does what, and when, makes the plan hard to misread. Adapt the timing to your own release cadence.
| When | Action | Output to record |
|---|---|---|
| Code freeze | Stop merging to the release branch | Commit hash of the release |
| 1 to 3 business days before | Run validation with `RunLocalTests` | Job ID, validation date |
| Same day | Confirm status with `sf project deploy report` | Pass or fail, coverage numbers |
| Window start | Check no other deployments to production since validation | Yes or no |
| Window | Run `sf project deploy quick` with the job ID | Deployment status |
| After the window | Smoke test and close the release | Sign-off |
The commit hash matters more than it may seem. It ties the validated job ID to a specific state of the source, so there is no doubt later about what was validated.
When quick deploy is not available
Plan for the case where quick deploy is rejected in the window. Typical reasons are:
- The validation is older than 10 days.
- The validation did not run tests, or the tests or coverage requirements did not pass.
- The job ID belongs to a different org than the one you are targeting.
- The validated deployment was already promoted.
You have two choices, and you should decide which one before the window, not during it:
- Revalidate and wait. Run a new validation, then promote it when it passes. This is safer, but it needs enough time in the window or an extended window.
- Run a full deployment with tests. Use
sf project deploy startwith the same manifest and--test-level RunLocalTests. This changes the org as soon as it passes, but it uses the full test run time inside the window.
State the decision rule in the runbook. For example: "If quick deploy is unavailable and more than two hours remain, revalidate. Otherwise postpone." Writing it down removes a stressful judgment call at the worst moment.
Edge cases to plan for
- Overlapping releases. Two teams may each hold a valid job ID for production. Promoting one changes production, and the other validation was checked against the older state. Sequence the releases and revalidate the second one if it touches related components.
- Hotfixes. An urgent fix can go in between your validation and your window. After a hotfix, check whether your validated deployment still makes sense. If the hotfix touched the same components, revalidate.
- Test flakiness. A test that passes only some of the time can fail a validation the day before the window. Fix or quarantine such tests early, since a failed validation costs a whole test run to repeat.
- Time zones. The 10-day period is measured by the platform, and your team may be spread across several time zones. Write the expiry date and time in UTC in the runbook.
- Change sets. Change sets use the same ideas through Setup. A change set validation can be promoted from Deployment Status with Quick Deploy while it is eligible. The same 10-day limit applies.
Exercise
Your team validated a release on Monday against production with RunLocalTests, and the validation passed. On Wednesday, a developer merges one more Apex class change to the release branch. The release window is Thursday night. What should you do, and why?
Show answer
Revalidate on Wednesday or early Thursday with the final contents. The Monday validation is a fixed snapshot of the components you sent, and it does not include the new Apex class change. Quick deploy would promote only what was validated, so the new change would be missing. Revalidating also gives you a fresh job ID and a fresh 10-day period. Record the new job ID and commit hash in the runbook, and keep the revalidation early enough to leave time to fix failures before the window.
Exercise
Write the rule you would put in a runbook for when quick deploy is rejected at the start of the window, and name one fact the rule depends on.
Show answer
Example rule: "If quick deploy is unavailable and at least as much time remains as the last full test run took, plus a margin, run a full deployment with RunLocalTests. Otherwise postpone and revalidate." The rule depends on the duration of the last full test run, which is visible in the validation report. Any rule is acceptable if it names a clear threshold, is decided before the window, and states what happens on each side of it.