Sub topic 13
Validation and test gates before release
This chapter assumes you know how a DevOps Center pipeline promotes work items from stage to stage. It also assumes you know Apex test basics and have used the Salesforce CLI. Here you will see where validation and tests act as gates, and how to check a change before you promote it.
Where gates sit in the pipeline
A gate is a check that must pass before a change moves forward. In DevOps Center, a promotion deploys the work item's changes to the next stage's org. That deployment runs the same checks as any Salesforce deployment. If a check fails, the change does not advance.
Production deployments need Apex tests. Lower stages, such as a UAT sandbox, can run them too, so you find problems before the final promotion.
Test levels
Salesforce deployments use a test level. The common ones are:
| Test level | What runs | Typical use |
|---|---|---|
| NoTestRun | No tests | Sandbox only |
| RunSpecifiedTests | Tests you name | Small, targeted changes |
| RunLocalTests | All tests in your org, except managed package tests | Standard gate before production |
| RunAllTestsInOrg | Every test, including managed packages | Rare, full regression |
Production requires at least 75% Apex code coverage across the org. Each class or trigger you deploy must also have coverage, and the tests must pass.
Validate outside DevOps Center
You can check a change with a validation-only deployment. It runs the full deployment and tests, then rolls back without saving anything. Run it against the stage's org with the Salesforce CLI:
sf org login web --alias uat
sf project deploy start --source-dir force-app --target-org uat --dry-run --test-level RunLocalTestsUse this before you promote a risky change. A failure here costs nothing, because no metadata is saved.
See what a promotion carries
Before promoting from UAT, list the commits that are on the UAT branch but not yet on main:
git fetch origin
git log --oneline origin/main..origin/UATEach line is a commit that would travel with the promotion. If you see a commit you did not expect, check it before you release. Another work item may have been promoted ahead of its dependencies.
Common errors
- Coverage below 75%. Add or fix tests for the classes you changed. Tests that already exist in the org still count.
- Tests pass in the sandbox but fail in production. Tests may rely on sandbox data. Create the data inside the test instead.
- Missing dependency. A work item references a field or class that only exists in another, unpromoted work item. Promote them together or in order.
- Failure at production only. Production may hold validation rules or triggers that the sandbox lacks. Run a validation against production before the release window.
Exercise
A work item passes in UAT with NoTestRun, but the production promotion fails on test coverage. What should you change in the pipeline process?
Show answer
Run the UAT stage with RunLocalTests, or run a validation-only deployment with that test level, so the same tests that gate production also gate the earlier stage. Then fix the coverage before promoting again.