Sub topic 2
Running a Validation from the Salesforce CLI
Assume you know basic Salesforce metadata, sandbox and production orgs, and the sf CLI. A validation-only deployment checks whether metadata can deploy to the target org. It runs the selected tests and deployment checks, but does not save the metadata.
Run the validation
Create a manifest that lists the Apex classes and tests you want to validate:
<?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>Choose a test level based on the deployment and your release policy:
| Test level | What runs | Typical use |
|---|---|---|
| RunLocalTests | Tests created in the current organization | Most production deployments |
| RunSpecifiedTests | Only the tests named in the command | Controlled, targeted deployments |
| RunAllTestsInOrg | All tests, including managed-package tests | Broadest test run |
Run a validation against the production alias:
sf project deploy validate \
--manifest manifest/package.xml \
--test-level RunLocalTests \
--target-org prodThe command may wait for completion or return a deployment job ID while the server continues processing.
Read the result and keep the job ID
Use the returned job ID to inspect the validation:
sf project deploy report \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prodLook for these results:
- Overall status: succeeded or failed.
- Component errors, such as invalid metadata or missing dependencies.
- Test failures and their messages.
- Apex code coverage results.
- The deployment job ID, which begins with
0Af.
Save the exact job ID with the release record. A later quick deploy must refer to the validated deployment, not a newly assembled package.
When quick deploy is available
A validation is generally eligible when:
- It succeeded against the intended target org.
- It used an allowed production test level.
- Its metadata and test results are still valid.
- No relevant changes invalidate the validation.
- The validation has not passed its eligibility period.
Quick deploy uses the stored validation results, so Salesforce does not run the Apex tests again. If eligibility is missing, inspect the validation status and errors before starting a new validation.
Exercise
Does a successful validation change production?
Show answer
No. It checks the deployment and stores results. A separate quick deploy applies the validated package.