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

Test coverage

Hello all,

my first thread in the community forum...:smileyvery-happy:

I wrote a trigger in the sandbox environment and a test class that invokes that trigger.
the trigger works perfectly, and got 100% coverage.

the problem is that other triggers that were already in which I didn't wrote/change, didn't  pass the tests.

those triggers were already in the environment, I didn't change a thing. I assumed that someone wrote test classes for them in order to deploy them to the production.

anyway, I understood that I need to write a test class that invokes the trigger I just wrote, which I did.

what am I missing here?

Thank a lot , Assaf
Hey Assaf,

My initial thoughts is that you only ran the test methods for your individual trigger through the Eclipse IDE and for this reason all of the other code would have appeared to fail testing as the full suite of test classes would not have been run. 

The easiest way to run all test classes is through the standard user interface.  If you navigate to setup --> Develop --> Apex Classes and hit the 'Run All Tests' button I'm thinking your problems will go away.


Ok, from what I can gather from your post, I'm assuming that all these issues are in sandbox, and you haven't yet made an attemp to deploy the code to production.  I mean, the existing tests are failing in sandobx, right?  If this is the case, then try removing YOUR trigger and test code, and then try running the existing tests.  If they still fail, that means you will have to fix the already written test code (that you did NOT write).  There could be numerous reasons why the tests that had earlier passed, fail now.  Here's a couple I can think of from the top of my head:

  • The test code does NOT create all the test data, and instead uses hard-coded IDs from Production.  The test data being used in the test code should always be created in the test code.  Actual data should never be used for testing.  All data/ records created in test code are mock records, and are not persistent.
  • The test code was not written to cater for large sets of data.  At the time the triggers were deployed, there was a small set of data, which the test code processed correctly.  But now, with bigger data set, the test code hits governing limits.

There could be others, but these are generally the two main reasons for such situations.  Hope this helps!

thank you.

I did run the test trough the GUI as you said and you were right.
I'm getting 88% code coverage vs 17%(!!!!!!) in eclipse.

why is that?

Am I going to have some troubles deploying it to the production through the eclipse?


Eclipse will only pass a single file to the test API and therefore will not run all test classes within an instance.  When you deploy to an environment the platform will run all test classes currently in that environment (unless it is being overwritten by a new file with the same name) and within the deployment payload you have created.

thanks :smileyhappy: