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
Rich TolockaRich Tolocka 

Salesforce gives inconsistent answers on code test coverage

Hello-

Was hoping someone could help me. Currently, I'm unable to deploy code as Salesforce reports insufficient code coverage.

Specifically, I have a trigger called 'ResourceTrigger'. The Developer's console reports 87% code coverage on this class. Picture below.

User-added image

But when I attempt to deploy (or validate the deployment of the trigger), the system prevents me from deploying, saying I have zero percent coverage for ResourceTrigger. This is contradictory.

User-added image

Any ideas or help is appreciated.
Dan1126Dan1126
Hi Rich,

Possibly different data and configurations in your production environment are lowering the coverage. The link below has a good explanation. Hope this helps!

https://success.salesforce.com/answers?id=90630000000hHVZAA2
Amit Chaudhary 8Amit Chaudhary 8
Make sure SeeAllData should be false in your test class . And for Trigger min 1% code coverage should be there.

If SeeAllData = true then Your test methods depend on data in the organization, so you probably have a more robust data set in Sandbox than in Production. A best practice is to create all your test data within your test method, 

 
pti69pti69
Yes agreed. Some data is causing some/many of the lines  in your code to be skipped. Put either SeeAllData=false, or make sure data exists that meets all the IF-Else conditions etc in your code.
Rich TolockaRich Tolocka
Thanks all. I tried SeeAllData=false, but that didn't seem to work. The error (0% test coverage on ResourceTrigger) remains.

All of the data used in the test is created within the ResourceTrigger test itself. This is a brand new class (Resource) and therefore there is no data in our production instance that could possibly be used to test this class other than what I've created within the test itself, as test data.

I remain very confused about how such variant numbers (0% vs 87%) could be produced. I could understand some small difference but one system reports very healthy test coverage and the other, absolutely none. Yikes.

I've read a good deal of the Salesforce documentation on this but it appears quite light on what is actually happening behind the scenes. I did find an article surrounding ensuring that your trigger test exercies bulk data scenarios - so I added coverage for that - but it didn't move the numbers at all.

Any other ideas? Much appreciated, thanks for all your responses.

Rich