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
Yousef Bayari 7Yousef Bayari 7 

Apex Code Coverage issue

Hello 

 I have 95% covergae in production , and I moving classes/triggers that have (97%) coverage in dev. 

Whan I deploy in production , I am getting the error 

Code Coverage Failure
Your organization's code coverage is 73%. You need at least 75% coverage to complete this deployment.

what am I missing here !?

Thanks 

Best Answer chosen by Yousef Bayari 7
CJWilderCJWilder

Have you checked the coverage on all your triggers in your production org? I pushed a trigger to prod a few months back that did not have the required coverage and it was allowed in. That surprised me so I started googling and found this blog by Jeff Douglas http://blog.jeffdouglas.com/2009/03/04/how-to-deploy-apex-without-test-coverage/  (http://blog.jeffdouglas.com/2009/03/04/how-to-deploy-apex-without-test-coverage/)

It seems that coverage can be viewed as an average across all your triggers. So even it that trigger has 95% coverage it could be possible that the new code was enough to lower your overall average based on all your triggers coverage.

All Answers

Sameer PrasonnSameer Prasonn
Hi Yousef,

Just try to touch each aspect while writing in each scenario of functionality. after that error remain the same then use fake test coverage(i++) to complete the code coverage. hope that make sense.
James LoghryJames Loghry
It's likely due to one and/or two things:
  1. The code between your sandbox and production is out out of date.  You have more code in production than in sandbox, perhaps.
  2. Your unit tests were written to use existing data, either using a really old api version that tended to rely on existing data, or by setting the SeeAllData=true annotation.  Data between sandbox and production is likely different, and if your tests rely on existing data, then your code and test code would behave differently.   
See the following doc (or do a quick google search) for more information: http://www.salesforce.com/us/developer/docs/apex_workbook/Content/apex_testing_intro.htm
Yousef Bayari 7Yousef Bayari 7
Thanks guys , 

 Actually I am using SeeAllData=true annotation , but this wasnt an issue and I was able to move my code before, I need to to See AllData because in my test I am creating a record in an object and there are some lookup fields need to be filled,.  and the values I am selecting in TEST I am sure they are existing in PROD , for example ( Urgency = LOW,HIGH,MEDIUM) thats a lookup table and has same values in all environments. 

Sameer what is "fake test coverage(i++)" and how can I use this ? 


Thanks 

Vinnie BVinnie B
My only guess would be that production is really not at 95%.  I've found that what the system tells me about where my organization is at and where I'm actually at are often off, but not by the amount you mention.

How did you arrive at 95% code coverage in Production?  Is that what the system is telling you or did you calculate that?  Remember that during deployment ALL of your classes are tested.
Gigi.OchoaGigi.Ochoa
You are probably having some test class(es) fail early on and not touching all the code it is testing after it failed.  Do you have validation rules in production that you do not have in sandbox?  Your deployment results should tell you if any test methods failed.

Have you run all test in production prior to deployment to make sure everything is OK?
Sameer PrasonnSameer Prasonn
Hi Yousef,

There are time when we are running out of time and deployment is urgent and code coverage is not upto the standard(75% and above).
then we can use this stretegy. it is not a good practice however it can allow you to cover the code-coverage.

for this we need to create a method in the code and call that method from test class. which almost cover the code coverage.

here i have an example fake method

public void fake_method(){
                 Integer i;
                 i++;
                 i++;
                 i++;
                 i++;
                 ......
}

We need to make sure that each increment statement must be in new line.

hope this resolve the query.
CJWilderCJWilder

Have you checked the coverage on all your triggers in your production org? I pushed a trigger to prod a few months back that did not have the required coverage and it was allowed in. That surprised me so I started googling and found this blog by Jeff Douglas http://blog.jeffdouglas.com/2009/03/04/how-to-deploy-apex-without-test-coverage/  (http://blog.jeffdouglas.com/2009/03/04/how-to-deploy-apex-without-test-coverage/)

It seems that coverage can be viewed as an average across all your triggers. So even it that trigger has 95% coverage it could be possible that the new code was enough to lower your overall average based on all your triggers coverage.

This was selected as the best answer
Yousef Bayari 7Yousef Bayari 7
Thanks Guys for your help ,  I had to rewrite my test class and make sure I cover every single line in the class. 

Aniket Supe 3Aniket Supe 3
Line: 5, Column: 1
Method does not exist or incorrect signature: [EmailManager].sendEMail(String, String, String)