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
ptepperptepper 

Weird behavior with triggers preventing deployment of a separate class

Hi,

I have a class I'm updating on my Sandbox (a VF custom controller). There are several triggers in this sandbox, each of which has a corresponding class with a a test method in it.

In Eclipse, when I right click the one class I want to deploy and deploy to server I get a failure, it says because of the triggers:

Code coverage issue, class: Trigger1 -- Test coverage of selected ApexTrigger is 0%, at least 1% test coverage is required
Code coverage issue, class: Trigger2 -- Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
Code coverage issue, class: Trigger3 -- Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
Code coverage issue -- Average test coverage across all Apex Classes and Triggers is 70%, at least 75% test coverage is required

However, all of these triggers have 100% coverage by the corresponding classes. I'm just selecting the one class I want to deploy, not the other classes with the triggertest methods.

I managed to get it to deploy by selecting the whole 'classes' folder in Eclipse. The first time I did this, all the triggers and other classes now showed that they pass the unit tests, but the class I was trying to deploy did not. I looked in the logs and it said it was because of a "System.Exception: Too many query rows". So I changed the code so that there were limits in my queries (there were no limits before, and it used to work).

When I changed that, then selected the 'classes' folder and delpoyed, it deployed fine. 

Anyone know why there is this weird behavior? Why does it tell you your triggers are failing and your class to deploy is passing, when that is not the case? It was this other error all along, but I had to deploy the folder to see it. Is this a bug?

Sorry if the solution to this is posted elsewhere, but I can't find it.

thanks,
-paul
bob_buzzardbob_buzzard

Just to clarify, do you see these errors when you are deploying from the sandbox to your production org?  

 

When you deploy to production, even for a single class, every unit test in your org namespace is executed.  In order to pass the tests, all triggers must have some coverage.  

 

If your tests are pulling in existing data, you may find that you'd tipped over a limit and thus your unit tests couldn't run to completion, resulting in a lack of coverage. 

ptepperptepper

bob_buzzard wrote:

 Just to clarify, do you see these errors when you are deploying from the sandbox to your production org?  

 

When you deploy to production, even for a single class, every unit test in your org namespace is executed.  In order to pass the tests, all triggers must have some coverage

 


Yes, I was deploying from sandbox to production.

 

The test method was pulling in existing data on the one that had that error, and thats why it got that governor limit violation. I hadn't noticed it before because the live limit in VF controllers is 10,000 records, but the limit in tests is 500 records. I'm still not sure how to get tell it to pull < 500 when in a test and <10,000 when live, so it's just pulling <500 now.

 

However, the real problem was that I couldn't see that that was happening when I ran the tests -- it was not telling me that I had that error, it just kept saying 0% coverage on all my trigger unit tests when I clicked the class and selected deploy from the context menu. It only told me the error when I selected the classes folder and deployed from there.

 

 

bob_buzzardbob_buzzard
There was a thread with something similar a few weeks back - no errors, but only showing 50% or so covered.  I'm pretty sure the last time I deployed using the IDE it showed me unit test failures.  Weird.