You need to sign in to do that
Don't have an account?
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
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
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
If yes then please add seeAllData=false and create test data in your test class
No I am not using it.
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
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();
}
}
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 ?
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
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
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