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
Itzik WinogradItzik Winograd 

Code Coverage drops when deployed

Hi all!
I'm trying to deploy a class and it's test class from sandbox.
Class B17 stands on 75% coverage, and tests runs perfectly in console. Class B17Test is the test class. I made an outbound change set that holds BOTH classes.
When deploying in production, i choose Run specified tests and mentioning only B17Test class.  It fails over "Code Coverage Error" - only 5% is covered.
How can it be if i have 75% in sandbox? And what should i do to successfully deploy the classes?

It IS my firs Class deployment, so any help would be MUCH appreciated! :)
Best Answer chosen by Itzik Winograd
José Manuel Martín FluxáJosé Manuel Martín Fluxá
Ok, nothing was changed at the body class... but what about the data in your live environment? :) 

Did you use the @isTest(SeeAllData=true) annotation?, the test results can differ depending on which data is available in the organization. If the records referenced in a test don’t exist or have changed, the test fails or different code paths are executed in the Apex methods; so, the code coverage can decrease a lot. If you put this annotation (SeeAllData=true), please, try to remove it and make another deployment. 

Did you install some App Exchange Managed Package or did you make changes at some profile's settings? 

Regads,
 

All Answers

José Manuel Martín FluxáJosé Manuel Martín Fluxá
 Hi Itzik, I suggest you to go to this thread : 

https://developer.salesforce.com/forums/?id=906F0000000B27eIAC

They cover there the same issue. 

 
Itzik WinogradItzik Winograd
Thanks José!
I have encountered this thread before. It seems that a specific change happened during this thread's liftime.
Both classes were deployed few month ago with 75% succesfully, and nothing was changed at the B17 class body but a replacment of a formula field with regular number field - with equivalent tests added to maitain 75% covarege.
Any suggestions?
José Manuel Martín FluxáJosé Manuel Martín Fluxá
Ok, nothing was changed at the body class... but what about the data in your live environment? :) 

Did you use the @isTest(SeeAllData=true) annotation?, the test results can differ depending on which data is available in the organization. If the records referenced in a test don’t exist or have changed, the test fails or different code paths are executed in the Apex methods; so, the code coverage can decrease a lot. If you put this annotation (SeeAllData=true), please, try to remove it and make another deployment. 

Did you install some App Exchange Managed Package or did you make changes at some profile's settings? 

Regads,
 
This was selected as the best answer
Itzik WinogradItzik Winograd
Thanks José, I think this is it - some additional fields and field-dependencies were added to the live environment.
I don't get any specific errors (e.g. validation or PB errors), but I understand from your answer that this intense decrease is probably due to difference between environment..
We'll probably go to full sandbox refresh for this.
THANKS again!
José Manuel Martín FluxáJosé Manuel Martín Fluxá
Perfect! If you can make a full sandbox refresh maybe you don't have that coverage problem. But you only can refresh one time at a month (I think). If it's posibble for you, I suggest to make the fields changes in sandbox before and then, move the changes to the live environment (sometimes is better to make again the changes in live, instead to make a new outbound). 

Best regads,
Jose Fluxa