You need to sign in to do that
Don't have an account?
100% coverage in Sandbox only 66% coverage in production
Trying to figure out why my production coverage is now only getting 66% coverage. The code is identical to the Sandbox? Any suggestions?
Trigger:
trigger OSC_Activty_Event on Event (after update) {
2
3 for (Event updatedEvent : trigger.new) {
4 for(Event olduEvent : trigger.old){
5 if (updatedEvent.Sales_Call_Completed__c != olduEvent.Sales_Call_Completed__c){
6 for(Account a : [SELECT id, Last_Sales_Call__c FROM Account WHERE Account.id = :updatedEvent.AccountId]){
7
8 a.Last_Sales_Call__c = updatedEvent.Completed_Date_Time__c;
9 update a;
10
11 }
12
13 }
14 }
15
16
17 }
18 }
Apex Class:
@isTest
private class OSC_Event_Test {
static testMethod void myUnitTest() {
// TO DO: implement unit test
Event ev = [Select id,Sales_Call_Completed__c from Event where Sales_Call_Completed__c = 'No' limit 1];
ev.Sales_Call_Completed__c = 'Yes'; ev.All_Communities_Objective__c = 'Sell a Paid Model';
try{
update ev;
//System.assertEquals('This is a test');
}
catch(System.DmlException e){
System.debug('we caught a dml exception: ' + e.getDmlMessage(0));
}
}
}
Hi All,
I believe that is because you are querying data in test class.As in Sandbox you have that data it is working fine but while in production data doesn't exist the best way to resolve this issue to create Event record with all required fields which match your query cirteria to fire your trigger in test method.
e.g
@isTest
private class OSC_Event_Test {
static testMethod void myUnitTest() {
Event ev=new Event();
ev.Sales_Call_Completed__c='No';
insert ev;
try{
ev.Sales_Call_Completed__c = 'Yes';
ev.All_Communities_Objective__c = 'Sell a Paid Model';
update ev;
}
catch(System.DmlException e){
System.debug('we caught a dml exception: ' + e.getDmlMessage(0));
}
}
}
Hopefully this will help you
Thanks
All Answers
You can see the results of the test run (including which lines were not covered) by clicking on the code coverage link in the Apex trigger list. If you can't deploy to Prod because of the coverage level, you can see the same results in the ChangeSet validation results, or in the ForceIDE error dialog (expand test results)
But why would it be covered in the Sandbox and not Production? That is what I don't understand.
Hi Rung,
Even i faced the same issue, it might be salesforce summer'13 bug.
Try re deploying the code to production and check the coverage again.
Hope this helps
Hi All,
I believe that is because you are querying data in test class.As in Sandbox you have that data it is working fine but while in production data doesn't exist the best way to resolve this issue to create Event record with all required fields which match your query cirteria to fire your trigger in test method.
e.g
@isTest
private class OSC_Event_Test {
static testMethod void myUnitTest() {
Event ev=new Event();
ev.Sales_Call_Completed__c='No';
insert ev;
try{
ev.Sales_Call_Completed__c = 'Yes';
ev.All_Communities_Objective__c = 'Sell a Paid Model';
update ev;
}
catch(System.DmlException e){
System.debug('we caught a dml exception: ' + e.getDmlMessage(0));
}
}
}
Hopefully this will help you
Thanks
+1 for aNsag.
The testmethod is querying for existing data. In the Sandbox, this will find one Event and Account. In Production, it will find different records. To be sure you are running the same test, create the records you need right in the testmethod. Note that for this trigger, you'll need to create an Account with certain properties, then create an Event and update it.