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
hgolovhgolov 

Unable to deploy to production, not enough coverage across organization

Hi All,

 

First of all, thank you for taking the time to read my post.

I wrote an apex class and tried to deploy it via the eclipse ide. However, I got the following error :

 

 Average test coverage across all Apex Classes and Triggers is 74%, at least 75% test coverage is required.

 

I then wrote a test class to test many classes and triggers that weren't properly covered, but I can not get that to deploy either. I tried going into the production project in Eclipse, but it doesn't save to server and gives the same error on deployment. I also tried deleting some unused classes via Eclipse, but that isn't reflected in the production environment.

 

Does anyone have any idea how I can solve this?

 

Thanks again

bob_buzzardbob_buzzard

So if you try to deploy your test class you still see an error that there isn't enough coverage to allow that to deploy?  This sounds like you might be experiencing some errors when running the tests - existing data interfering, for example.  Have you looked at the log output when you attempt to deploy?

hgolovhgolov

Thanks for your reply! I haven't checked the logs, but I do not get any errors on deployment in the deploy page in prod, or in the ide - only the aformentioned one about the code coverage.

bob_buzzardbob_buzzard

Does the figure change?  I.e. if you try to deploy your code you get an error for 74% versus 75% required.  If you try to deploy your test do you get the same figures?  That smacks that tests are failing somewhere along the line.    What happens if you just run all tests in your production org?

hgolovhgolov

No, the figure doesn't change. I can't run the tests right now because we have some batch jobs running and that causes the schedulers' tests to fail - but otherwise there are no fails. Could it be that the test class I wrote just doesn't bring the total coverage high enough?

bob_buzzardbob_buzzard

It could be, but I'd have expected the test figure to increase, unless you have so much code that the increase isn't significant.

 

Did you write your test class in a sandbox?  If so, did the percentage coverage increase there for all tests once it was written?

hgolovhgolov

The sandbox that I used is not the only one in my org. There seems to be only 53% (!!) coverage in my sandbox, and it is not affected when I comment out my test method.

bob_buzzardbob_buzzard

Have you checked that the method is being treated as a test - i.e. it shows up in the list of tests run?

colemabcolemab

If you run the tests from the web interface in the sandbox, then any failures / exceptions will show on the results page.  Also on that page, you will see each class listed with a coverage % next to it. 

 

If you click the percentage, you should get a pop-up window that highlights which parts of your class got exceuted during the test.  

 

Looking at this can help you write a new test case and/or modify an existing one to get the code coverage that you need to deploy to production.

 

Just a thought.