Sub topic 6
Reading results and keeping the job ID
This chapter assumes you can authorize an org with sf, know what a manifest is, and have already started a validation as covered in the previous chapter. Here you will learn to read what a validation reports and to record the one value that quick deploy needs later: the job ID.
What a validation returns
A validation runs as an asynchronous job on the target org. The CLI either waits for it to finish or returns early, depending on the --wait flag. Either way, Salesforce creates a deployment record with an ID that starts with 0Af. That ID is the job ID.
The job ID is the only handle you have on the validation. A later quick deploy refers to this ID, not to your manifest or your local files. If you lose it, you can usually find it again (see below), but it is better to record it as soon as the validation starts.
Reading the CLI output
When a validation finishes, the CLI prints a summary. The parts to check are:
- Status.
Succeededmeans every component and every required test passed.Failedmeans at least one did not.Canceledmeans someone stopped the job. - Component failures. Each failed component is listed with its type, name, line, and error message.
- Test failures. Each failed test shows the class, method, error message, and a stack trace.
- Test totals. The number of tests run, how many failed, and the total run time.
- Code coverage warnings. Classes or triggers below the required coverage are listed here.
If you did not wait for the job to finish, check on it with the report command:
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodReplace the placeholder with your own job ID. The command works for validations and for real deployments.
Component results versus test results
Deployment problems fall into two groups, and they need different fixes.
| Result type | What it tells you | Typical fix |
|---|---|---|
| Component failure | The metadata itself could not be saved, for example a missing field or a compile error | Fix the metadata or add the missing dependency to the manifest |
| Test failure | The code compiled, but a test assertion or an unhandled exception failed | Fix the code or the test, or find the data or configuration difference in the target org |
| Coverage warning | Tests passed, but a class or the org overall is below the coverage threshold | Add or improve tests |
Read component failures first. A compile error in one class can cause many tests to fail, and fixing the compile error clears all of them.
Finding the job ID later
If you started the validation in a script or a different terminal, you have two ways to recover the ID:
- Run
sf project deploy reportwithout a job ID. The CLI uses the most recent deployment it recorded locally. - In the org, open Setup, search for Deployment Status, and look in the Succeeded list. A validated deployment is labeled as a validation, and its ID is shown in the details.
The second method is also the right check when a teammate ran the validation, because the CLI only remembers deployments started from your machine.
Confirming the validation is usable
A Succeeded status is necessary but not sufficient for quick deploy. Before you rely on the job ID, confirm three things:
- The job was a validation, not a real deployment.
- It ran with a test level that quick deploy accepts, such as
RunLocalTestsorRunSpecifiedTestswith sufficient coverage. - It succeeded recently. The exact window is covered in the next chapter.
Common mistakes
- Copying a truncated ID. A job ID has 15 or 18 characters. Copy the whole value and check it against the report output.
- Using the wrong org. The ID is only meaningful in the org where the validation ran. Pass the same
--target-orgto every command. - Treating a failure as a partial success. A validation that fails saves nothing and cannot be quick deployed, even if most tests passed.
- Not saving the ID with the release notes. Put the job ID, the validation time, and the test level in your release ticket so the person deploying does not have to search.
Exercise
A validation shows status Succeeded, but the output lists one class below the coverage threshold as a warning. A colleague asks you to move on to quick deploy with this job ID. What should you check first, and why?
Show answer
Check whether the validation ran with a test level and coverage that meet the production requirement. Classes below the required coverage can cause the real deployment to be rejected, and a validation that does not satisfy the coverage rules is not eligible for quick deploy. If the class is below 75 percent, add tests and run a new validation. Then record the new job ID.
Exercise
You started a validation from a CI server yesterday and lost its job ID. Name two ways to find it.
Show answer
Open Setup, search for Deployment Status, and find the validation in the Succeeded list to read its ID. Or, if the CLI on the same machine recorded the deployment, run sf project deploy report without a job ID to see the most recent one.