Sub topic 11
Validating first, then quick-deploying
This chapter assumes you can run sf project deploy start with a manifest, you know the Apex test levels, and you have authorized a production org.
Why validate first
A production deployment that runs all local tests can take a long time. If it fails near the end, you lose that time. If it succeeds, you may be holding up a release window while the tests run.
Validation splits the work in two. You run the deployment as a check-only job, with the tests, ahead of time. Later, at the moment of release, you quick-deploy the validated job. Salesforce skips the tests the second time.
The difference from --dry-run is the intent. sf project deploy validate produces a job ID that sf project deploy quick can use. A dry run is for checking a deploy, not for releasing it.
The workflow
Run the validation against the target org:
sf project deploy validate --manifest manifest/package.xml --target-org production --test-level RunLocalTests
sf project deploy quick --job-id 0AfXXXXXXXXXXXXXXX --target-org productionReplace the placeholder with the ID that the validate command prints. The quick deploy changes the org without running the tests again. The deployment still appears in the org's deployment history.
Finding the job ID later
If the validate command stopped waiting, or you ran it in another session, look up the ID with the status commands:
sf project deploy report --use-most-recent
sf project deploy quick --use-most-recent --target-org production--use-most-recent refers to the last deployment job that the CLI tracked. Be careful with it on a shared machine. If another deployment ran after your validation, "most recent" is no longer your validation. Passing --job-id is safer.
Conditions for a quick deploy
A quick deploy is accepted only when all of these hold:
- The validation succeeded and ran tests. A validation with no tests is not eligible.
- Code coverage requirements were met during that validation.
- The validation finished within the last 10 days.
- You deploy to the same org that you validated against.
The quick deploy takes the components that were validated. You cannot change the source or the manifest at this step. If you change any code, validate again.
Common errors
- Job not eligible for quick deploy. The validation ran without tests, the tests failed, or the job ID belongs to a regular deploy. Re-run
validatewith a suitable--test-level. - Validation expired. More than 10 days have passed. Validate again.
- Org changed in between. Other deployments to the org can change the result. If the quick deploy fails for this reason, validate again. A quick deploy is not a guarantee against interference.
- Wrong org. The job ID is tied to the org that ran it. Check
--target-org.
Exercise
You validated a manifest against production with RunLocalTests on Monday. On Wednesday, a developer fixes a typo in one Apex class. Can you quick-deploy Monday's job ID to release the fixed class? What do you do instead?
Show answer
No. A quick deploy releases only the components that were validated, so the fix is not included. Validate again with the updated source and a test level that runs tests, then quick-deploy the new job ID.