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
Nida Khan 5Nida Khan 5 

Deploying a Trigger with its test class has 0% code coverage in production.Urgent help

Hello All,

I am deploying a trigger with its test class having good coverage in Sandbox, but when I am deploying it production its showing 0% code coverage.
Please give your suggestions for the same.

Thanks,
Nida
Best Answer chosen by Nida Khan 5
Nida Khan 5Nida Khan 5
Hello friendz,

The issue is resolved now, I found somework arounds which may help others.

1) If the code is making use of Global Picklists, and if you have created the same in production make sure to enable all picklist values.
As- GoTo RecordType --> Click the edit link before your picklist from the list of picklists and drag the values from left side to Right Side and hit Save.

2)  Make sure all the fields whether they belong to trigger(code) or test case are visible to the user from whom you are doing deployment.

3) If your test class includes object and fields from managed package, make sure your user in production have licence to that package else deploy with user who has license.

4) Never assign your testclass variables with a value of 'test'.

Note: All though its not a good practice to use (SeeAlldata = true) , but sometimes we need to use due to some manage package limitations.So make sure your queried data exist.

Please mark it as best answer, so that it may be helpul for others.

Thanks,
Nida

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Are you using seeAllData=true in your test class ?

If yes then please add seeAllData=false and create test data in your test class
 
Nida Khan 5Nida Khan 5
Hi Amit,

No I am not using it.

 
UC InnovationUC Innovation
Would you mind posting your test class?  Otherwise, it's hard to try to guess at what could be the problem.
Amit VaidyaAmit Vaidya
Hi Nida,

If you have written the test class for any perticular trigger then please check you are deploying your test class with the said trigger code.

Thank you,
Amit
Nida Khan 5Nida Khan 5
Here is the code, 
with this piece of code I am covering 4 triggers in Sandbox

/* This test class covers triggers : 

updateExpAndEvent
SetPoApprover
UpdateFieldsOfAccount
UpdatePurchaseOrderStatus 
*/

@isTest(seeAlldata = false)
public class allTriggerTest{
    public static testmethod void myUnitTest1(){
        Test.StartTest();
        
        ID rectypeid = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Organization').getRecordTypeId();
        
        Campaign ca = new Campaign(Name='Test Campaign');
        insert ca;
        
        Local_Organizing_Committee__c epc = new Local_Organizing_Committee__c();
        epc.Campaign__c = ca.Id;
        insert epc;
        
        Account acc = new Account();
        acc.name = 'tesname';
        acc.recordtypeId = rectypeid;
        insert acc;
        
        c2g__codaGeneralLedgerAccount__c gel = new c2g__codaGeneralLedgerAccount__c();
        gel.c2g__ReportingCode__c = '1111';
        gel.c2g__Type__c ='test';
        insert gel;
        
        Purchase_Order__c po = new Purchase_Order__c();
        po.Event__c = ca.Id;
        insert po;
        
        Purchase_Order_Line_Item__c pitem = new Purchase_Order_Line_Item__c();
        pitem.Purchase_Order__c = po.id;
        pitem.Expense_Type__c = '5144 - Property Taxes';
        //pitem.Event_Committee__c = epc.Id;
        pitem.Event_Planning_Committee__c = '6 ISC - Participt Svcs';
        pitem.Event_Budget_Grouping__c = 'ISC - Admin';
        insert pitem;
        
        PO_Invoice__c pinv = new PO_Invoice__c();
        pinv.name = 'INV-12345';
        pinv.Purchase_Order__c = po.Id;
        pinv.Inv_Date__c  = date.today().adddays(90);
        pinv.Inv_Number__c  = 'InvNum';
        insert pinv;
        
        product2 p2=new product2();
        p2.Name='test';
        insert p2;

test.stopTest();
}
}
Amit Chaudhary 8Amit Chaudhary 8
Hi Nida Khan 5,

Can you please check below point
1) I hope you are deploying test class with trigger in change set together ?
2) Is any error is coming while validating change set or package ?
3) Please check "Organization" record type is avaliable in production ?

 
Nida Khan 5Nida Khan 5
Hi Amit,

1) Yes I am deploying them together.
2) No error in trigger run, but only this code coverage error while test case run.(I am choosing the option run specified test)
3) Yes, its available in production

Thanks
Amit VaidyaAmit Vaidya
Hi Nida, This can be an recursion issue as well. Can you update that respective object trigger so that it will execute only one time and check if it covering any code. Please also apply debugs where necessary. Thanks, Amit
Nida Khan 5Nida Khan 5
Hello friendz,

The issue is resolved now, I found somework arounds which may help others.

1) If the code is making use of Global Picklists, and if you have created the same in production make sure to enable all picklist values.
As- GoTo RecordType --> Click the edit link before your picklist from the list of picklists and drag the values from left side to Right Side and hit Save.

2)  Make sure all the fields whether they belong to trigger(code) or test case are visible to the user from whom you are doing deployment.

3) If your test class includes object and fields from managed package, make sure your user in production have licence to that package else deploy with user who has license.

4) Never assign your testclass variables with a value of 'test'.

Note: All though its not a good practice to use (SeeAlldata = true) , but sometimes we need to use due to some manage package limitations.So make sure your queried data exist.

Please mark it as best answer, so that it may be helpul for others.

Thanks,
Nida
This was selected as the best answer
Amit VaidyaAmit Vaidya
Thanks Nida for sharing your efforts.
Lawrence-AccentureLawrence-Accenture
Nida,

When you were getting the 0% code coverage, were your test classes failing? Or were all test classes passing, but you still received the 0% coverage error at the end?

-L