Sub topic 13
Validate first, then quick deploy
This chapter assumes you can run sf project deploy start, you know the four test levels, and you know the 75% coverage rule. It shows how to run the slow test step ahead of time, so the production release itself is short.
The problem: tests slow down the release window
A production deployment with Apex runs tests, and a large org can spend a long time on them. During that time the deployment holds a lock on the metadata it touches. A validation deployment lets you run the tests early, when nothing is at stake. A quick deploy then reuses the passing result.
Validation deployments
A validation deployment runs the same checks as a real deployment, including your chosen test level and the coverage check. It saves no changes to the org. Use sf project deploy validate:
sf project deploy validate --source-dir force-app --target-org my-prod --test-level RunLocalTestsThe command prints a job ID. Keep it, because the quick deploy needs it. If you lose it, sf project deploy report shows recent deployments in the org.
Quick deploy
A quick deploy takes a validation that passed and saves its changes without running the tests again:
sf project deploy quick --job-id <validated-deploy-job-id> --target-org my-prodYou don't pass --source-dir or --test-level. The validated job already defines both.
Conditions for a quick deploy
A quick deploy is refused unless the validation meets all of these conditions:
- The validation passed, with all tests green and coverage requirements met.
- It ran at
RunLocalTestsorRunAllTestsInOrg. A validation atNoTestRunhas no test result to reuse. - It finished within the last 10 days. After that, validate again.
- The target org has not changed in a way that affects the validated components.
Where this fits in a pipeline
A common pattern uses three steps:
- The CI server validates on every merge to the release branch, at
RunLocalTests. - The team records the job ID of the last green validation.
- In the release window, someone runs the quick deploy with that ID.
The release window shrinks from "all tests plus deployment" to "deployment only". A failed validation also surfaces problems days before the release instead of during it.
Common mistakes
| Mistake | Result | Fix |
|---|---|---|
| Validating at `RunSpecifiedTests` or `NoTestRun`, then running a quick deploy | The quick deploy is rejected | Validate at `RunLocalTests` or `RunAllTestsInOrg` |
| Waiting longer than 10 days | The validation has expired | Run a new validation |
| Changing source after validating | The change is not deployed | Validate again |
| Passing `--test-level` to `deploy quick` | The flag is not part of the command | Remove it and set the level on the validation |
Exercise
Your team validated a production release on Monday at RunLocalTests and it passed. On Tuesday a developer fixes a typo in a Visualforce page that was part of the release. The release window is Friday. What should you do, and why?
Show answer
Run a new validation from the updated source and use its job ID for the quick deploy on Friday. The Monday validation tested the old source, so a quick deploy from it would not include the typo fix. The new validation is still well inside the 10-day limit, and the quick deploy on Friday will skip the tests.