• Alonb-plimus
  • NEWBIE
  • 10 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

 

Task - update Opportunity__c lookup field on case - from a text field on case with an opportunity id. This is my first coding task - but unsure how to troubleshoot the following issue.

 

Test code covers 100% in sandbox and manual testing of trigger works as required.  But ony 72% covered in production and it fails to delploy.

 

Here is class:

 

public class ImpCaseOppUpdate {
public static void ImpOppUpdate(Case[] oids) {
for (Case c :oids){
c.Opportunity__c = c.Opportunity_id_w__c;
}
}

}

 

 

Here is trigger:

 

trigger ImpCaseOppTrigger on Case (before insert,before update) 
{
Case[] oids = Trigger.new;
ImpCaseOppUpdate.ImpOppUpdate(oids);

}

 

Here is test class:

 

@isTest
private class ImpOppCaseTestClass{
 static testMethod void validateImpOppCase(){
Case c = new Case(Opportunity__c=Null,Opportunity_Id_w__c='006R0000007Jt1j');
System.debug('Opportunity before inserting new: ' +c.Opportunity__c);

insert c;

c=[SELECT Opportunity__c FROM Case WHERE Id=:c.id];
System.debug('Opportunity after trigger fired:' +c.Opportunity__c);

System.assertEquals('006R0000007Jt1j',c.Opportunity__c);
}
}

 

Here are the errors after attempting to deploy to production.

 

MassUpdateSimpleControllerTest.singleUpdateTest()

 

Failure Message: "System.NullPointerException: Attempt to de-reference a null object", Failure Stack Trace: "Class.MassUpdateSimpleController.__sfdc_fieldName: line 111, column 1 Class.MassUpdateSimpleControllerTest.singleUpdateTest: line 33, column 1"

 

Deploy Error

 

Average test coverage across all Apex Classes and Triggers is 72%, at least 75% test coverage is required.