Sub topic 14
Validate once, quick deploy later
This chapter assumes you have read the chapters on pull request validation and deploying on merge. You should be comfortable with check-only deployments, --test-level, and GitHub environments.
The problem quick deploy solves
A production deployment with RunLocalTests can take 30 minutes or more. The org is busy for that whole time, and a late test failure wastes all of it. Quick deploy splits the work in two. You run the slow tests once, in a validation. Later you commit that validated result without running the tests again.
How it works
A validation is a check-only deployment that runs tests and saves its result in the org under a job ID. If the validation passed and met the coverage requirements, Salesforce can promote it with a quick deploy. The promotion takes a few minutes instead of a full test run.
Step 1: validate and capture the job ID
sf project deploy validate runs a check-only deployment and prints the job ID. The --json flag makes the ID easy to extract.
set -o pipefail
JOB_ID=$(sf project deploy validate \
--source-dir force-app \
--test-level RunLocalTests \
--target-org target \
--wait 60 \
--json | jq -r '.result.id')
echo "Validated job: $JOB_ID"set -o pipefail makes the script fail when the validation fails. Without it, jq succeeds and hides the error.
Step 2: quick deploy by job ID
The quick deploy workflow below is started by hand. It takes the job ID as an input and runs in the production environment, so any approval rule on that environment applies.
name: Quick deploy to production
on:
workflow_dispatch:
inputs:
job-id:
description: Job ID of a passed validation
required: true
jobs:
quick-deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Salesforce CLI
run: npm install --global @salesforce/cli
- name: Authenticate to production
env:
SFDX_AUTH_URL: ${{ secrets.SFDX_AUTH_URL }}
run: |
echo "$SFDX_AUTH_URL" > authurl.txt
sf org login sfdx-url --sfdx-url-file authurl.txt --alias target --set-default
rm authurl.txt
- name: Quick deploy
env:
JOB_ID: ${{ inputs.job-id }}
run: sf project deploy quick --job-id "$JOB_ID" --target-org target --wait 30This workflow does not check out the repository. A quick deploy needs no source files, because the org already holds the validated package.
The job ID goes through an env variable and not directly into the shell script. That keeps a typed input from being run as a command.
Rules and limits
- Expiry: a validation can be quick deployed for 10 days. After that, validate again.
- Tests and coverage: the validation must have run tests and met the coverage requirement. A validation that skipped tests cannot be promoted.
- Same org: the job ID is only valid in the org where the validation ran.
- Fixed contents: a quick deploy ships exactly what was validated, not the current head of
main. If a later merge changes the code, validate again.
When to use it
Quick deploy pays off when production tests are slow, or when you must deploy in a short release window. For small orgs with fast tests, the extra workflow is not worth it, and deploying on merge is simpler.
Exercise
A validation passed on Monday. On Thursday a teammate merges another change into main. You run a quick deploy with Monday's job ID. Which code reaches production, and what should you do if you need the new change released too?
Show answer
Only the code validated on Monday reaches production, because a quick deploy ships the validated package and not the current head of main. To release the new change, run a new validation that includes it and quick deploy the new job ID.