I have written a following trigger code -
trigger manageEmailCases on Case (before insert)
{
for(Case thisCase : trigger.new)
{
if(thisCase.Origin == 'Call-Center')
{
// system.debug('Origin is Call Center');
// Check for invalid email account
if(!thisCase.SuppliedEmail.contains('directlineinc'))
{
if(!Test.isRunningTest())
{
thisCase.addError('Not saving e2c');
// thisCase.Support_Alert__c.addError('Not saving email2case');
}
}
}
}
}
I have this following EXISTING testMethod written for some ANOTHER class -
@IsTest(SeeAllData=false) public static void testHandleExistingCase ()
{
// Set up the object.
CallCenterCaseNotification testObj = new CallCenterCaseNotification();
testObj.populateSreContactInfo(Datetime.valueOf('2013-08-20 16:35:00'));
String description = 'account_name: testcorp customer_name: sammmmmm ' +
'customer_phone: +1 (707) 477-3205 ' +
'customer_email: something' +
'service_impacted: yes case_id:123 ' +
'case_description: testing';
// Set up parameters for the call to method.
Case existingCase = new Case();
existingCase.Origin = 'Call-Center';
existingCase.Subject = 'Test case';
existingCase.Status = 'Closed';
// Select an SRE to use as the OwnerId
User testOwner = [SELECT Id FROM User WHERE UserRoleId = '00E60000001GX26EAG' LIMIT 1];
existingCase.OwnerId = testOwner.Id;// testObj.UNASSIGNED_OWNER_ID;
existingCase.Description = description;
insert existingCase; // Need to insert, because methods do a Query for this
// case object. So cannot mock out.
String customerInfoForSMS = '\ncustomer_name \n@ account_name \n' +
' 123-234-1234';
testObj.handleExistingCase(new Case[] {existingCase}, existingCase,
'no', 'P3 - Normal', customerInfoForSMS,
'[email protected]');
}
}
When I test the class which has this testMethod, it gives me following error, which is also not allowing me to deploy -
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, manageEmailCases: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.manageEmailCases: line 9, column 1: []
Kindly advise what could be wrong with my trigger written above.