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
Rakshith RamachandraRakshith Ramachandra 

Failed deployment even though 100% of the code to be deployed is Covered

My production system is at 75% and I'm trying to deploy a trigger. It's 100% covered. The deployment fails saying code coverage is 74%.

I'm wondering how the code coverage decreased when I'm testing all the lines I'm trying to push from Sandbox. 

Any pointers?
Adrian  GawryszewskiAdrian Gawryszewski
Maybe you are deploying other elements that decrease the total code coverage. That's one of the options. The other thing I'm not sure how it works, but sometime on sandboxes the code coverage isn't calculated correctly, so even though it may be a fresh copy of a prod it will show coverage at totatly different rate. In general try to cover other classes, that's the only option for you now. In general keeping code coverage level at 75% is not a safe option. Try to go over 80% and that issue should never happen.
Rakshith RamachandraRakshith Ramachandra
Agreed. However, I'm deploying only a trigger and a test class which tests the working of the trigger. The Production system itself shows that the code coverage for the trigger is 100%. I'm using the Eclipse IDE and I'm sure I'm not deploying anything extra which decreases the overall coverage.
Adrian  GawryszewskiAdrian Gawryszewski
Well maybe there is a bug with the way salesforce calculates the coverage itself. It doesn't change the fact that unfortunatelly you have to increase that rate otherwise it will not let you to deploy anything. If it looks dodgy it is also a good idea to create a support case to Salesforce and notify them about it. Maybe they will be able to find the reason.
Rakshith RamachandraRakshith Ramachandra
Just created one. Thanks for your help!
Amit Chaudhary 8Amit Chaudhary 8
Hi Rakshith,

Please follow some best pratice for Deployment. I hope that will help you
1) Always try to maintain the production code coverage near 80% so that you will never face this type of issue
2) Weekly or monthly always check code coverage in prod and sandbox
3) You can download the code coverage of each class with below app exchange product

Let us know if this will help you.

NOTE:- I hope you added the Test class also in you change set while deployment ?
Rakshith RamachandraRakshith Ramachandra
Thanks Amit for your feedback. Yes, I've included the test class in the deployment.
I just installed your app on my Production system. Nice work

Rakshith RamachandraRakshith Ramachandra
Quick pointer though. The report only works when I go Run all tests. If I do that, I'd be able to check the coverage directly from Developer console. Is there a way the app runs the tests by itself and calculates the covarage? Just an idea. Thanks anyway
Amit Chaudhary 8Amit Chaudhary 8
Run All test is required. In developer console you can see the code coverage of each class only. But you can not download the result in XLS.

So please download the report and check which all test classess having low code coverage . Please increase the code coverage of that classes and include that classes in package an validate your change set again