"The deployment failed and there are no errors" is a common complaint. It usually means the failure is in a part of the result that the tool didn't print. This post maps where a Metadata API deployment keeps its errors, its test failures and its coverage warnings, using Salesforce's documentation of the deployment result.
The result object
You start a deployment with deploy(). To follow it, you call checkDeployStatus() in a loop. It returns a DeployResult, and you check its done field to see whether the deployment has finished.
The DeployResult has the overall outcome. The detail is in its details field, and that field is empty unless you ask for it: details is only returned if you set includeDetails to true in the checkDeployStatus() call. A script that never sets it sees the summary and none of the lists below.
What is inside the details
details holds a DeployDetails entry. These are the parts that matter:
| Part | What it holds |
|---|---|
componentFailures |
One DeployMessage per component that failed, with the file name, the line number and the problem description |
componentSuccesses |
One DeployMessage per component that deployed |
runTestResult |
The Apex test results, when tests ran as part of the deployment |
retrieveResult |
The retrieve result, only if you asked for a retrieve alongside the deploy |
Each DeployMessage has a problem type of either Warning or Error. Salesforce notes that before API version 18.0 there was no such distinction, and every problem was treated as an error that stopped the deployment.
Timing: what you see while it runs
While a deployment is still in progress, DeployDetails contains only componentFailures. The other fields fill in after the deployment finishes. So a status check made mid-run can show failures but no test results yet, and that is expected.
Tests live one level further down
runTestResult is a RunTestsResult, and that is where the test side of a failure sits:
- Failing tests are listed in its
failures. - Coverage problems are listed in its
codeCoverageWarnings, an array of coverage warnings.
This is why a deployment can fail while componentFailures is empty and no test failed. If the coverage rule wasn't met, for example a class in a RunSpecifiedTests run that none of the named tests covered, the evidence is in runTestResult.codeCoverageWarnings, not in the component errors or the test failures.
A checklist for "it failed with no errors"
- Did you call
checkDeployStatus()withincludeDetails=true? - Is
componentFailuresempty? If so, look atrunTestResult. - In
runTestResult, checkfailuresfirst, thencodeCoverageWarnings. - Was the deployment still running when you looked? Check
done, and look again when it is true. - If you used
RunSpecifiedTests, compare the classes in the package with the classes your named tests cover.
One caution about versions
The component lists were first on the deployment result itself, and later moved into details. Salesforce says this changed in API version 29.0. If you are reading an old script or an old blog post, check which layout it assumes before trusting where it looks for errors.
I build Diffbridge, a Salesforce deployment tool. Nothing above needs it. If you spot a mistake in the result details, tell me and I'll fix it.