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
Jorgan StrathmanJorgan Strathman 

Production Code Coverage: 0%

"Your overall code coverage is currently 0%"

HUH? I was very unpleasantly surprised to find out, when I went to deploy my first custom class from SB to PROD, that my PROD is returning 0% code coverage (without my class!). This isn't possible... is it?

I am using out-of-the-box Salesforce with only one managed package: The Foundation's Nonprofit Start Pack v3. No custom code, repeat no code, no validations... the org is new. I have run all tests and I physcially see the majority of the managed TCs pass but it makes no difference at all. I just keep staring at 0% org wide coverage. I opened a CASE with SFDC Support and they turned me away. I went out to the forums and tried everything... Developer Console, Workbench... I have cleared the ApexCodeCoverage table and the ApexCodeCoverageAggregate table. I have compiled and recompiled... no difference. My zombie org sits at 0% code coverage and despite having only ONE custom class and TC in SB at 92% coverage... my hands are tied. I can't deploy anything.

PLEASE HELP.
Best Answer chosen by Jorgan Strathman
Jorgan StrathmanJorgan Strathman
UPDATE: RESOLUTION

After considering all other non-managed functions in the system operating on the primary objects in the code (Lead, Account, Contact and Opportunity). I tried to run down all validation rules, workflows, process builders and any other custom code (non-managed on those items - there was none). It dawned on me that Standard Duplicate Management Rules might also be running and could adversely affect my custom Test Class by blocking creation of test data (which essentially it was). I deactivated the duplicate management rule, re-compiled the classes, cleared the test history, ran all tests. I then re-validated the inbound changeset which passed at 91%. I cleared the history, re-compiled and re-ran tests. I then re-estimated and came up with 91% code coverage (post deployment). I then flipped the Duplicate Management Rule back on, cleared the test history, recompiled the classes and ran all tests. Code coverage came up as 1%.

It appears that when the currently active Account duplicate rule is turned on / active the org code coverage is calculated as 1%. However, when the currently active Account duplicate rule is turned off / deactivated the org code coverage is calculated as 91%.

FOR ANYONE OUT THERE HEAD SCRATCHING like I was, don't forget Duplicate Management Rules! (It cost me about 24 hours of my life!) 

All Answers

Steve CairneySteve Cairney
What's the developer console telling you when you run your test class?
Jorgan StrathmanJorgan Strathman
Well I can only run my custom TC in the SB. When I do I am getting 91% coverage. The problem is in Prod I have 0% so when I try to deploy the percent goes up because my TC is so high but it's not enough to get to 75%... I just have no clue why my prod is reading 0% - it doesn't make any sense....
Jorgan StrathmanJorgan Strathman
In case it isn't clear I am calculating code coverage without including my custom code in Prod... So right now in prod it is just managed code from Salesforce but my coverage is 0%...
Steve CairneySteve Cairney
I'm currently pushing a change set from my SB to Production. I can confirm that in my production it tells me that my code coverage is just 4%

However, I can deploy (although I'm not hitting the 75% for another reason). It might be a bug.

Try and make a  outgoing changeset that includes your class and your test class (and any related neccessary objects etc) and see if it validates
Mahesh DMahesh D
Hi Jorgan,

Make sure that you are including the Apex Class / Apex Trigger which you have written for your functionality into outbound Changeset along with your Test Classes then it will run all the test classes while deploying into Production.

First try to deploy any configuration component like a custom field / custom object / validation rule / work flow. By doing these we will know that there is no issue with the current Production environment.

Regards,
Mahesh
Jorgan StrathmanJorgan Strathman
UPDATE: RESOLUTION

After considering all other non-managed functions in the system operating on the primary objects in the code (Lead, Account, Contact and Opportunity). I tried to run down all validation rules, workflows, process builders and any other custom code (non-managed on those items - there was none). It dawned on me that Standard Duplicate Management Rules might also be running and could adversely affect my custom Test Class by blocking creation of test data (which essentially it was). I deactivated the duplicate management rule, re-compiled the classes, cleared the test history, ran all tests. I then re-validated the inbound changeset which passed at 91%. I cleared the history, re-compiled and re-ran tests. I then re-estimated and came up with 91% code coverage (post deployment). I then flipped the Duplicate Management Rule back on, cleared the test history, recompiled the classes and ran all tests. Code coverage came up as 1%.

It appears that when the currently active Account duplicate rule is turned on / active the org code coverage is calculated as 1%. However, when the currently active Account duplicate rule is turned off / deactivated the org code coverage is calculated as 91%.

FOR ANYONE OUT THERE HEAD SCRATCHING like I was, don't forget Duplicate Management Rules! (It cost me about 24 hours of my life!) 
This was selected as the best answer
B_BajajB_Bajaj

@Jorgan,

I am facing the same issue experienced by you.

No Custom Code in Prod (NPSP installed)- Code Coverage 0 % while running all classes even I have deactivated all Duplicate & Matching Rules in org.

While deploying inbound ChangeSet- Failed low code coverage 62%, I have only 100 lines of codes moving from SB to Prod so I am not sure what is happening.

Please help.

Thanks,
Bhisham

Mahesh DMahesh D
Hi Bhisham,

Please open a separate discussion and paste your class and test class so that it will be easy to help you.

Regards,
Mahesh
Lawrence-AccentureLawrence-Accenture
Hi Jorgan,

With the Duplicate & Matching Rules enabled, were your test classes failing? Or were they passing and you just got the 0% code coverage at the end?

I'd expect that if Salesforce was blocking the addition of a duplicate record, it would generate an error and the test class would fail. Is that not what you were seeing?

-L