[SalesForce] Average test coverage across all Apex Classes and Triggers is x%, at least 75% test coverage is required

When I try to deploy a change set, the validation step (and deploy) fails and I receive this error message:

Average test coverage across all Apex Classes and Triggers is x%, at least 75% test coverage is required.

I already encountered it, but I had additional error messages guiding me to know which class prevent deployment. In this case, I went in sandbox and looked at every Apex class included in the change set, executed all the tests and they are all at least over 80%.

Is there a way to see which class is blocking deployment?

Best Answer

Unfortunately change sets are fairly limited in the information they provide about why a deployment fails. You don't get access to the deployment logs, and hence can't see what sort of code coverage you're getting.

If I have a deployment that fails like this I do the following

1. Run all tests in production.

You may have tests that are failing, commonly due to the addition of a new validation rule (among a million other reasons). If this is the case take steps to fix the test failures, such as turning off the offending validation rules, until you're able to get your code coverage up enough for you to deploy.

2. Run all tests in the source org

It's possible that you're deployment is causing test to fail. Running all tests in the source sandbox will let you know if that's the case. Once you fix the failures in the sandbox and confirm you've got enough code coverage build a new change set and redeploy.

3. Deploy with ANT / Eclipse / Maven's Mate

If you're still getting good test coverage on both sides you'll need to dig a little harder. If you deploy with ANT / Eclipse / Maven's Mate you'll get deployment logs which can give you some better insight into what's causing the low code coverage.

Related Topic