[SalesForce] Code Coverage Error While Deploying

I want to deploy some of my classes (which are above 83% each) from sandbox to production. But it is showing code coverage error while deploying through change set.

There are other classes without test class in sandbox. By mistakenly I clicked run all tests in developer console. Is that the reason for showing code coverage error?

In my class, code coverage is showing like thisenter image description here

But it should should show like this..enter image description here

Best Answer

By running all tests in Sandbox is not going to affect anything while deploying in production env.

When you deploy a changeset it runs all tests in the prod env and its got nothing to do with classes in Sandbox without test class.

you can restrict the running of all test classes while deploying by also specifying only a single or multiple test classes by choosing the Run specified tests radio button and giving comma seperated names of the test classes to run.

Only the tests that you specify are run. Provide the names of test classes in a comma-separated list. Code coverage requirements differ from the default coverage requirements when using this level in production. The executed tests must cover the class or trigger in your change sets with a minimum of 75% code coverage. This coverage is computed for each class or trigger individually and is different from the overall coverage percentage.

enter image description here

Also take a look at the answers in the link below, there could be a pointer as to why your code is failing in prodn. Can't get code coverage over 75% when deploying to production

Related Topic