+ Start a Discussion
SArorasSAroras 

How to increase code coverage for below issue

Hi All,

I am stuck with this code coverag issue for last 4 days. Its continuously flashing as :
User-added image
This coverage is of Sandbox org. In Production coverage is 86%.

Please help.
NagendraNagendra (Salesforce Developers) 
Hi Saroras,

Sorry for this issue you are facing.

Please follow some best practices 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
https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000DXzlpEAD

Run All test is required. In the 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 classes having low code coverage. Please increase the code coverage of that classes and include that classes in the package a validate your changeset again

Let us know if this will help you.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra
 
SArorasSAroras
Hi Nagendra,

Code coverage is coming fine and more than 75% for all classes. Even overall org coverage for both sandbox and production is 86%.
Still when I am deploying getting code coverage error.
Ajay K DubediAjay K Dubedi
Hi SAroras,
One most important thing I would recommend is to check that all test classes are creating their own test data and do not rely on org's data.

Then check the below link:
https://help.salesforce.com/articleView?id=000335222&type=1&mode=1

If the issue persists then the issue may be because of the text class errors that are not listed while running the test classes such as not using unique 
username while inserting a new user for test purpose or the user trying to deploy classes which has a reference to a certain field that he doesn't have access. 
This usually occurs when we are deploying the changes running the specific test classes (4th option). If we are running all the test classes, the errors 
occurring in test class will be shown. So it is recommended you deploy the changes by running all the test classes.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
SArorasSAroras
Hi Ajay,

Tried with what you have mentioned, but everytime same error is popping up. Implemented  every possible thing, not sure what I am missing. :(
SArorasSAroras
Hi All,

Thanks for your inputs. 
By making some additions of i++ in the code, i was able to increase the coverage and deploy.