You need to sign in to do that
Don't have an account?
Bob
Apex Trigger Test Lines Not Covered
I have a trigger with a test method that has lines of code not covered. I was wondering if anyone could help fill in the blanks. Lines, 16,18,20,21,23,24 are not covered. I am also using the test for another trigger, but wanted to add coverage into the test for my new trigger too.
New Trigger
trigger Trigger_PreferredSP on Case (before update) {
List<String> accountList = new List<String>();
for (Case c : Trigger.new)
accountList.add(c.AccountId);
// Query Accounts
Map<Id, Account> accountMap = new Map<id, Account>([SELECT OwnerId,Preferred_SP__c,Shipping_Country__c FROM Account WHERE id =: accountList]);
// Set Service Provider
for (Case c : Trigger.new){
Account a = accountMap.get(c.AccountId);
if(a != null){ //Checks to see if the case has an account.
if(a.Shipping_Country__c != 'USA')
if(a.Shipping_Country__c != 'CAN')
if ( c.Service_Provider__c == null)
c.Service_Provider__c = a.Preferred_SP__c ;
else if(c.AccountId == null & a.Preferred_SP__c == null )
c.Service_Provider__c = null ;
}
TEST METHOD
@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',Shipping_Country__c= 'USA', 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= 'USA';
acc.Shipping_Country__c= 'CAN';
update acc;
Case cse = new Case( Status='Open', Origin='Parts Support - Web', Subject='Parts', Web_Case_Type__c='Part Support',Service_Provider__c='0017000000WitqP');
insert cse;
cse.Status = 'Open';
cse.Origin = 'Parts Support - Web';
cse.OwnerId='00G70000001JGIA';
cse.Web_Case_Type__c='Part Support';
cse.Service_Provider__c = '0017000000WitqP';
update cse;
cse.Status = 'Open';
cse.Origin = 'Tech Support- Web';
cse.OwnerId='00G70000001hJGH';
cse.Web_Case_Type__c='Tech Support';
update cse;
test.stopTest();
}
}
New Trigger
trigger Trigger_PreferredSP on Case (before update) {
List<String> accountList = new List<String>();
for (Case c : Trigger.new)
accountList.add(c.AccountId);
// Query Accounts
Map<Id, Account> accountMap = new Map<id, Account>([SELECT OwnerId,Preferred_SP__c,Shipping_Country__c FROM Account WHERE id =: accountList]);
// Set Service Provider
for (Case c : Trigger.new){
Account a = accountMap.get(c.AccountId);
if(a != null){ //Checks to see if the case has an account.
if(a.Shipping_Country__c != 'USA')
if(a.Shipping_Country__c != 'CAN')
if ( c.Service_Provider__c == null)
c.Service_Provider__c = a.Preferred_SP__c ;
else if(c.AccountId == null & a.Preferred_SP__c == null )
c.Service_Provider__c = null ;
}
TEST METHOD
@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',Shipping_Country__c= 'USA', 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= 'USA';
acc.Shipping_Country__c= 'CAN';
update acc;
Case cse = new Case( Status='Open', Origin='Parts Support - Web', Subject='Parts', Web_Case_Type__c='Part Support',Service_Provider__c='0017000000WitqP');
insert cse;
cse.Status = 'Open';
cse.Origin = 'Parts Support - Web';
cse.OwnerId='00G70000001JGIA';
cse.Web_Case_Type__c='Part Support';
cse.Service_Provider__c = '0017000000WitqP';
update cse;
cse.Status = 'Open';
cse.Origin = 'Tech Support- Web';
cse.OwnerId='00G70000001hJGH';
cse.Web_Case_Type__c='Tech Support';
update cse;
test.stopTest();
}
}
if(a.Shipping_Country__c != 'USA')
if(a.Shipping_Country__c != 'CAN')
You are not doing anything yet you have these conditions. Either they are unneccessary or you forgot the processing blocks if the conditons are met.