function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Allen2Allen2 

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..
Adilson Arcoverde JrAdilson Arcoverde Jr
Hi Amy2,

A few tips that could help you:
  1. You forgot to create Country_Mapping__c instances. Custom settings are not visible, unless you set your test class to SeeAllData=true
  2. Does your user have all field permissions?
  3. Could you reply this post with your code using the code sample button (on editor pallete). It will be easier to help you.
Regards.
Abdul KhatriAbdul Khatri
What is the recordtype value in the following Label? Is it matching to the one "Technical" you are inserting with in the Test Class
System.Label.RecordtypeId_of_NonserviceCase
Also looks like Country_Mapping__c is a custom settings. Can you please make sure theser settings are filled with values.

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.
c1.Area__c = 'Billing';
c1.Sub_Area__c = 'Credit Note';
update c1;