The independent daily for Salesforce admins, developers and architects

Curated by Abhinav (opens in a new tab)

Validate ahead of the release window, then quick deploy without re-running tests (opens in a new tab)

You will learn what conditions a validation must meet to be promoted by quick deploy, including the 10-day limit and coverage rules, and how to structure a release around it.

Why read this

You will also see a CLI caveat about validating packages with no tests.

  1. Validate ahead of the window against the target
  2. Check the validation passed and note its ID
  3. Quick deploy that ID inside the window
  4. Validate again if the package or target changes
The validate-then-quick-deploy workflow for a release window

Production deployments that run Apex tests are slow, and the release window is short. Salesforce lets you run a deployment as a validation, also called a check-only deployment, which runs everything a real deployment would, tests included, but saves nothing in the org. If the validation passes, you can later promote it with a quick deploy, which deploys the validated components without running the Apex tests again. The Metadata API calls this deployRecentValidation(), the Salesforce UI offers it on the Deployment Status page, and the CLI uses sf project deploy validate followed by sf project deploy quick.

Salesforce sets several conditions. The components must have validated successfully for the target environment within the last 10 days, and the Apex tests in the target org must have passed as part of that validation. Code coverage must also be met: with all tests or all local tests, overall coverage must be at least 75% and Apex triggers must have some coverage; with RunSpecifiedTests, each deployed class and trigger must be at least 75% covered individually. Salesforce says a validation with passing tests only sometimes qualifies, so the author advises confirming it rather than assuming. Trailhead’s guidance adds that you should not deploy again or make major changes to the org in between.

Two consequences follow. A validation without tests cannot be promoted this way, because the quick deploy skips tests that the validation already ran, so there is nothing to skip. The tests chosen at validation time are the tests you get, and a quick deploy does not add or change them. If the per-class coverage rule fails under RunSpecifiedTests, the quick deploy is unavailable, so it is better to discover that during validation than inside the window. The suggested workflow is to validate ahead of the window against the same target with the test level you will rely on, check that it passed, note its ID, then quick deploy that ID inside the window. If the package or target changes, validate again. The 10-day limit is the main thing to watch, since a validation run before a long weekend may have expired.

The author also reports that sf project deploy validate rejected –test-level NoTestRun in their CLI run. To check a package with no tests, sf project deploy start –dry-run –test-level NoTestRun performs a check-only deployment, but nothing can be quick deployed afterwards. Some Stack Exchange answers report that a CLI –dry-run is not treated as a validation by sf project deploy quick, so use sf project deploy validate when planning a quick deploy and check this against your CLI version.

Read the original at dev.to (opens in a new tab)

Worth reading?