function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rakshana Cube84Rakshana Cube84 

Code coverage issue on deployment of Apex trigger even 87% in sandbox

Hi All,
I am deploying an apex trigger on contact object which has covered both after & before trigger. By the way, I have written the test class for that (It has so many If conditions) so test class code is very lengthy. I have done with that 87% code coverage. My production org overall percentage is 84%. But now I'm deploying my trigger along with the test class, the error is throwing out as Code Coverage Error and I'm not seeing any further errors in the deployment status. Please help me out to resolve it.

Thanks in advance,
Rakshana 
Raj VakatiRaj Vakati
The reason might be because of the other test class or your test class is not having enough data to pass the test data 

In the Sandbox the apex code and test classes show up with a 100% code coverage, still with the 100% coverage in Sandbox it does not mean that the Production will generate the same 100% percent during deployment. The overall code coverage of other existing components (trigger and classes) in production can be below 75%.

https://help.salesforce.com/articleView?id=000335002&type=1



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.

https://salesforce.stackexchange.com/questions/232152/code-coverage-error-while-deploying