Sub topic 4
What a validation does and does not do
This chapter assumes you can authorize an org with the Salesforce CLI (sf), and that you know what Apex classes, triggers, and tests are. You should also know that production deployments require Apex tests and code coverage.
What a validation is
A validation is a deployment run with the "check only" option. Salesforce runs the full deployment process against the target org. It resolves dependencies, compiles Apex, checks that the metadata is valid, and runs the Apex tests you selected. At the end, it rolls everything back.
The result is a pass or fail report, plus a job ID. A passing validation tells you that the same deployment, with the same metadata, would succeed right now.
What changes in the org, and what does not
A validation does not save your metadata to the target org. After a validation, the org has the same classes, triggers, fields, and settings it had before.
Some things still happen:
- Apex tests run and consume test execution time. Tests can also create and roll back data, and they count against org limits while they run.
- The deployment appears in Deployment Status in Setup, with its own job ID.
- Salesforce records the validation result. This record is what makes quick deploy possible later.
| Aspect | Validation | Real deployment |
|---|---|---|
| Metadata saved to target org | No | Yes |
| Compiles Apex and checks dependencies | Yes | Yes |
| Runs Apex tests | Yes, at the chosen test level | Yes, unless it is a quick deploy |
| Produces a job ID | Yes | Yes |
| Can be promoted by quick deploy | Yes, if it passes and is recent | Not applicable |
Why this matters
A validation moves the slow, risky part of a release out of the release window. Running tests in a large org can take a long time. If a test fails during the real deployment, you are fixing it while users wait. With a validation, you find the failure days earlier.
The manifest used in this tutorial
The examples use a small manifest. It lists one Apex class and its test class.
<?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>A validation reads this manifest the same way a real deployment does. The next chapter runs it with the CLI.
Limits of a validation
A passing validation is a snapshot, not a guarantee.
- It reflects the target org at the time it ran. If someone changes the target org afterward, for example by deploying other metadata that touches the same components, the result may no longer apply.
- It does not prove behavior beyond your tests. Only the tests you ran are checked. A weak test suite passes a broken change.
- It does not replace a test level choice. A validation with a lower test level can pass where a stricter one would fail. The test level you chose in the previous chapters decides what the pass means.
- It expires. A validation can be promoted by quick deploy only for a limited time. The eligibility rules are covered in a later chapter.
Common mistakes
- Treating a validation as a dry run with no side effects. Tests still execute in the org and use resources. Avoid running large validations during peak hours.
- Assuming a pass means the release is ready. If the target org changes between validation and release, validate again.
- Losing the job ID. Without the ID, you cannot quick deploy that validation. Record it as soon as the validation finishes.
Exercise
A teammate runs a validation against production, and it passes. Afterward, they check the org and find the new Apex class is not there. Is something wrong? What did the validation leave behind that is useful?
Show answer
Nothing is wrong. A validation rolls back all changes, so the class is not saved. It leaves a recorded result and a job ID, which a later quick deploy can use to deploy the same changes without rerunning the tests, if the validation is still eligible.
Exercise
Name two reasons a passing validation may not mean a release will succeed later.
Show answer
The target org may have changed since the validation ran, and the validation may have expired. Also, the tests you ran may not cover the behavior that breaks.