Hi Bob,There are errors in both Trigger_ChangeCaseCurrencyand Test_AssignWebCaseQueue. In Trigger_ChangeCaseCurrency you have not null checked your if condition. The trigger should be like this.
trigger Trigger_ChangeCaseCurrency on Case (before update) {
Set<Id> accIds=new Set<Id>();
for (Case cs: trigger.new){
accIds.add(cs.AccountId);
}
Map<Id,Account> accMap=new Map<Id,Account>([SELECT id, OwnerId,currencyisocode,Shipping_Country__c FROM Account WHERE Id IN :accIds]);
for (Case cs : trigger.new){
Account acc = accMap.get(cs.AccountId);
if(acc != NULL && (acc.Shipping_Country__c == 'GBR' || acc.Shipping_Country__c == 'IRL' )){
//update currency from Account
cs.currencyisocode=accMap.get(cs.AccountId).currencyisocode;
//set the curreny to GBP
cs.currencyisocode='GBP';
cs.Reason='Other';
}
}
}
Reason for the Exception :
In your test class you have not input Shipping_Accress__c value for the test account and also have not put the AccountId into your case.So accMap.get(cs.AccountId) returns NULL for the cases who dont have Accounts and your code was trying to get value of Shipping_Country__c from the NULL. Thats why you were getting these error.I have modifed your test class. But those are optional (if you want to test it properly) unless the Shipping_Country__c is a formula field. . This is your modified test class.
@isTest
private class Test_AssignWebCaseQueue {
static testMethod void myUnitTest() {
// TO DO: implement unit test
test.startTest();
Account acc = new Account( Name ='Key West Services', Market_Segment__c='Finance Company', Customer_Type__c='Finance Company', Preferred_SP__c ='0017000000WitqP', Registered_for_Seminar__c=true );
insert acc;
acc.Name='Key West Services';
acc.Market_Segment__c ='Finance Company';
acc.Customer_Type__c='Finance Company';
acc.Preferred_SP__c ='0017000000WitqP';
acc.Shipping_Country__c = 'GBR';
update acc;
Case cse = new Case( Status='Open', Origin='Parts Support - Web', Subject='Parts', Web_Case_Type__c='Part Support' AccountId=acc.Id);
insert cse;
cse.Status = 'Open';
cse.Origin = 'Parts Support - Web';
cse.OwnerId='00G70000001JGIA';
cse.Web_Case_Type__c='Part Support';
update cse;
cse.Status = 'Open';
cse.Origin = 'Tech Support- Web';
cse.OwnerId='00G70000001hJGH';
cse.Web_Case_Type__c='Tech Support';
update cse;
test.stopTest();
}
}
5 answers