You need to sign in to do that
Don't have an account?
Allen2
could any one help me to cover below apex trigger...
APEX TRIGGER
trigger Updatequickcontact on Case (after insert,after update)
{
if(IsUtil.adminByPass()) return;
// Bypass if dealer flag being updated
if(ClsStaticVariables.isUpdatingDealerFlag) return;
{
list<case> caslist1= new list<case>();
list<id> casids= new list<id>();
for(case cas :trigger.new)
{
if(Trigger.isInsert){
if(cas.recordtypeid ==System.Label.RecordtypeId_of_NonserviceCase &&
cas.Area__c == 'Billing'&&
cas.SubArea__c == 'Credit Note')
casids.add(cas.Id);
}
if(Trigger.isUpdate){
if(cas.recordtypeid ==System.Label.RecordtypeId_of_NonserviceCase &&
cas.Area__c == 'Billing' && (Trigger.oldMap.get(cas.id).Area__c != 'Billing') &&
cas.SubArea__c == 'Credit Note' && (Trigger.oldMap.get(cas.id).SubArea__c != 'Credit Note'))
casids.add(cas.Id);
}
}
if(casids.size() > 0)
caslist1=[select id,AccountId,Account.Billingcountry,ownerid from Case where id in: casids];
List<Country_Mapping__c> couns = Country_Mapping__c.getall().values();
List<task> tasklist = new List<task>();
system.debug('ssssssss'+caslist1.size());
String finalcoun;
for(case cc : caslist1)
{
system.debug('bbbbbbbbbbbb'+cc.Account.Billingcountry);
if(cc.Account.Billingcountry != null)
finalcoun = (cc.Account.Billingcountry).toUppercase();
for(Country_Mapping__c cs: couns)
{
system.debug('vvvvvv'+cs.PBCCC_Country__c);
if(finalcoun != null)
{
if(finalcoun.contains(cs.PBCCC_Country__c))
{
task kk =new task();
kk.whatid = cc.id;
kk.ownerid = cc.ownerid;
kk.Subject='Credit Note';
kk.RecordTypeid=System.Label.Task_Recordtpeid;
kk.Assign_To_Team__c = cs.PBCCC_Group_name__c;
kk.Assign_To_Team_check__c = false;
tasklist.add(kk);
}
}
}
}
system.debug('vvvvvv'+tasklist.size());
insert tasklist;
}
}
TEST CLASS
@isTest
private class Updatequickcontact_Test{
static testMethod void testUpdatequickcontact()
{
account a1 = new account(name='test account',Billingcountry = 'DENMARK');
insert a1;
contact con1 = new contact(accountid=a1.id,Phone='12345',lastname='test');
insert con1;
Id caseRecdTypeId = Schema.SObjectType.case.getRecordTypeInfosByName().get('Technical').getRecordTypeId();
List<Country_Mapping__c> couns = Country_Mapping__c.getall().values();
List<Case> caseList = new List<Case>();
case c1 = new case(
AccountId = a1.Id,
ContactId = con1.id,
status = 'new',
//Area__c='Collections',
Categories__c = 'Low/Medium Volume Mailing',
Reasons__c = 'Error Codes',
Sub_Reason__c = 'Bug Buddy',
recordtypeid = caseRecdTypeId,
//SubArea__c='Acceptance',
Country__c = 'DENMARK');
caseList.add(c1);
case c2 = new case(
AccountId = a1.Id,
ContactId = con1.id,
status = 'new',
Area__c = 'Billing',
Categories__c = 'Low/Medium Volume Mailing',
Reasons__c = 'Error Codes',
Sub_Reason__c = 'Bug Buddy',
SubArea__c = 'Credit Note',
RecordTypeId = caseRecdTypeId,
Country__c = 'DENMARK');
caseList.add(c2);
insert caseList;
Test.startTest();
task t1 = new task(Assign_To_Team__c = 'Group',
Subject = 'meeting',
Status = 'Not Started',
Priority = 'Medium');
insert t1;
c1.recordtypeid = caseRecdTypeId;
c1.Reasons__c = 'Error Codes';
c1.Sub_Reason__c = 'Bug Buddy';
update c1;
Test.stopTest();
}
}
bold, underlined part of trigger unable to cover... please help me..
trigger Updatequickcontact on Case (after insert,after update)
{
if(IsUtil.adminByPass()) return;
// Bypass if dealer flag being updated
if(ClsStaticVariables.isUpdatingDealerFlag) return;
{
list<case> caslist1= new list<case>();
list<id> casids= new list<id>();
for(case cas :trigger.new)
{
if(Trigger.isInsert){
if(cas.recordtypeid ==System.Label.RecordtypeId_of_NonserviceCase &&
cas.Area__c == 'Billing'&&
cas.SubArea__c == 'Credit Note')
casids.add(cas.Id);
}
if(Trigger.isUpdate){
if(cas.recordtypeid ==System.Label.RecordtypeId_of_NonserviceCase &&
cas.Area__c == 'Billing' && (Trigger.oldMap.get(cas.id).Area__c != 'Billing') &&
cas.SubArea__c == 'Credit Note' && (Trigger.oldMap.get(cas.id).SubArea__c != 'Credit Note'))
casids.add(cas.Id);
}
}
if(casids.size() > 0)
caslist1=[select id,AccountId,Account.Billingcountry,ownerid from Case where id in: casids];
List<Country_Mapping__c> couns = Country_Mapping__c.getall().values();
List<task> tasklist = new List<task>();
system.debug('ssssssss'+caslist1.size());
String finalcoun;
for(case cc : caslist1)
{
system.debug('bbbbbbbbbbbb'+cc.Account.Billingcountry);
if(cc.Account.Billingcountry != null)
finalcoun = (cc.Account.Billingcountry).toUppercase();
for(Country_Mapping__c cs: couns)
{
system.debug('vvvvvv'+cs.PBCCC_Country__c);
if(finalcoun != null)
{
if(finalcoun.contains(cs.PBCCC_Country__c))
{
task kk =new task();
kk.whatid = cc.id;
kk.ownerid = cc.ownerid;
kk.Subject='Credit Note';
kk.RecordTypeid=System.Label.Task_Recordtpeid;
kk.Assign_To_Team__c = cs.PBCCC_Group_name__c;
kk.Assign_To_Team_check__c = false;
tasklist.add(kk);
}
}
}
}
system.debug('vvvvvv'+tasklist.size());
insert tasklist;
}
}
TEST CLASS
@isTest
private class Updatequickcontact_Test{
static testMethod void testUpdatequickcontact()
{
account a1 = new account(name='test account',Billingcountry = 'DENMARK');
insert a1;
contact con1 = new contact(accountid=a1.id,Phone='12345',lastname='test');
insert con1;
Id caseRecdTypeId = Schema.SObjectType.case.getRecordTypeInfosByName().get('Technical').getRecordTypeId();
List<Country_Mapping__c> couns = Country_Mapping__c.getall().values();
List<Case> caseList = new List<Case>();
case c1 = new case(
AccountId = a1.Id,
ContactId = con1.id,
status = 'new',
//Area__c='Collections',
Categories__c = 'Low/Medium Volume Mailing',
Reasons__c = 'Error Codes',
Sub_Reason__c = 'Bug Buddy',
recordtypeid = caseRecdTypeId,
//SubArea__c='Acceptance',
Country__c = 'DENMARK');
caseList.add(c1);
case c2 = new case(
AccountId = a1.Id,
ContactId = con1.id,
status = 'new',
Area__c = 'Billing',
Categories__c = 'Low/Medium Volume Mailing',
Reasons__c = 'Error Codes',
Sub_Reason__c = 'Bug Buddy',
SubArea__c = 'Credit Note',
RecordTypeId = caseRecdTypeId,
Country__c = 'DENMARK');
caseList.add(c2);
insert caseList;
Test.startTest();
task t1 = new task(Assign_To_Team__c = 'Group',
Subject = 'meeting',
Status = 'Not Started',
Priority = 'Medium');
insert t1;
c1.recordtypeid = caseRecdTypeId;
c1.Reasons__c = 'Error Codes';
c1.Sub_Reason__c = 'Bug Buddy';
update c1;
Test.stopTest();
}
}
bold, underlined part of trigger unable to cover... please help me..
A few tips that could help you:
- You forgot to create Country_Mapping__c instances. Custom settings are not visible, unless you set your test class to SeeAllData=true
- Does your user have all field permissions?
- Could you reply this post with your code using the code sample button (on editor pallete). It will be easier to help you.
Regards.Please make a small correction in your test class while updating the case c1. I think you forgot changing the field names as you already inserted c1 with the same Reason and Sub Reason so there is no point of updating the same fields with the same values.