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
JaiJai 

could anyone please help me to get the code coverage for below class

apex class
------------------
public class EarlyAlertHandler {
    public static Boolean createticketflag = false;
    public static Id eUiteroRecordTypeId  =  Schema.SObjectType.Case.getRecordTypeInfosByName().get('Clinical Request').getRecordTypeId();
    public static Id csirEarlyId = Schema.SObjectType.Customer_Support_Internal_Request__c.getRecordTypeInfosByName().get('Early Alert System (EAS)').getRecordTypeId();
    Public static void createTicket1(List<case> caseList)
    {
        system.debug('case list '+caseList);
        String getRecordTypeInfosByName ='Clinical_Request';
        List<Case> newTicket = new List<Case>();
        List<Customer_Support_Internal_Request__c> newCsir = new List<Customer_Support_Internal_Request__c>();
        Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
        Map<ID, RecordType> recordTypeMap1 = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Customer_Support_Internal_Request__c']);
        Set<Id> accId = new Set<Id>();
        Set<Id> pid = new set<Id>();
        List<RecordType> listReTyp = new List<RecordType>([select Id,Name from RecordType where sObjectType='Case' AND Name LIKE 'Complaint Question%']);
        Boolean recFlag = false;
        for(Case cse : caseList)
        {
            for(RecordType rt : listReTyp)
            {
              if(cse.RecordTypeId == rt.Id)
              {
                  recFlag = true;
              }
                
            }
            
        }
        system.debug('recFlag '+recFlag);
        for(Case acCase : caseList)
        {
            accId.add(acCase.AccountId);
        }
        for(Case pids : caseList)
        {
            pid.add(pids.Patient__c);
        }
        Map<Id,Case> pidMap = new Map<Id,Case>(caseList);
        List<Case> cListMonth = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_MONTH];
        List<Case> cListQuarter = [Select id,Account.name,AccountId from Case Where AccountId = :accId and CreatedDate = THIS_QUARTER limit 100];
        List<case> cListPid = [select id,Patient__c from Case where Patient__c =:pid and CreatedDate = THIS_QUARTER limit 100];
        system.debug('Pids list '+cListPid.size());
        system.debug('Pidslist '+cListPid);
        system.debug('case list of month '+cListMonth.size());
        system.debug('cListQuarter '+cListQuarter.size());
        system.debug('cListQuarter1 '+cListQuarter);
        //Map<String,ID> ticketrecoedtypes = new Map<string,Id>([select name,Id from RecordType where sObjectType = 'Case']);
        for(case cs : caseList)
        {
            system.debug('1262 '+caseList);
            createticketflag = true;
            if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Aligner/retainer Fit Issues' 
                && cs.Complaint_Sub_Type__c =='Case Related'&&cs.Root_Cause__c =='Fit Issues due to Path of Insertion (whole arch)'
                                &&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2)))
                
               {
                   system.debug('Scenario2');
                   system.debug('csir rtype '+csirEarlyId);
                   Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
                   csir.RecordTypeId = csirEarlyId;
                   csir.Ticket__c = cs.Id;
                   csir.Description__c = 'early alert system test';
                   csir.Status__c = 'In Progress';
                   csir.Ticket_Origin__c = 'Phone';
                   csir.Category__c = 'Product Deficiency';
                   csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
                   csir.Complaint_Sub_Type__c = 'Case Related';
                   csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
                   csir.Trend_identified__c = '4 complaints per account in the same month';
                   csir.Account__c = cs.AccountId;
                   csir.Region__c = cs.Region__c;
                   csir.Patient__c = cs.Patient__c;
                   newCsir.add(csir);
                   system.debug('csir1 '+csir);
                   
               }
            else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Clinical Outcome' 
                && cs.Complaint_Sub_Type__c =='Aligner partially expressed  movements'&&cs.Root_Cause__c =='Movements expressed in half')
                    &&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
            {
                system.debug('Scenario3');
                Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
                   csir.RecordTypeId = csirEarlyId;
                   csir.Ticket__c = cs.Id;
                   csir.Description__c = 'early alert system test';
                   csir.Status__c = 'In Progress';
                   csir.Ticket_Origin__c = 'Phone';
                   csir.Category__c = 'Product Deficiency';
                   csir.Complaint_type__c = 'Clinical Outcome';
                   csir.Complaint_Sub_Type__c = 'Aligner partially expressed  movements';
                   csir.Root_Cause__c = 'Movements expressed in half';
                    csir.Trend_identified__c = '3 complaints per account in the same month';
                  csir.Account__c = cs.AccountId;
                   csir.Region__c = cs.Region__c;
                   csir.Patient__c = cs.Patient__c;
                   newCsir.add(csir);
                   system.debug('csir1 '+csir);
            }
            else if(recFlag == true&& (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' 
                && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Patient Records not properly examined')&&
                    (cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
            {
                system.debug('Scenario4');
                Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
                   csir.RecordTypeId = csirEarlyId;
                   csir.Ticket__c = cs.Id;
                   csir.Description__c = 'early alert system test';
                   csir.Status__c = 'In Progress';
                   csir.Ticket_Origin__c = 'Phone';
                   csir.Category__c = 'Product Deficiency';
                   csir.Complaint_type__c = 'Treatment Complaints';
                   csir.Complaint_Sub_Type__c = 'Design Execution';
                   csir.Root_Cause__c = 'Patient Records not properly examined';
                csir.Trend_identified__c = '3 complaints per account in the same month';
                csir.Account__c = cs.AccountId;
                   csir.Region__c = cs.Region__c;
                   csir.Patient__c = cs.Patient__c;
                   newCsir.add(csir);
                   system.debug('csir1 '+csir);
            }
                    else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' 
                && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Virtual Gingiva adjustment')
                            &&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
            {
                system.debug('Scenario5');
                Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
                   csir.RecordTypeId = csirEarlyId;
                   csir.Ticket__c = cs.Id;
                   csir.Description__c = 'early alert system test';
                   csir.Status__c = 'In Progress';
                   csir.Ticket_Origin__c = 'Phone';
                   csir.Category__c = 'Product Deficiency';
                   csir.Complaint_type__c = 'Treatment Complaints';
                   csir.Complaint_Sub_Type__c = 'Design Execution';
                   csir.Root_Cause__c = 'Virtual Gingiva adjustment';
                csir.Trend_identified__c = '3 complaints per account in the same month';
                csir.Account__c = cs.AccountId;
                   csir.Region__c = cs.Region__c;
                   csir.Patient__c = cs.Patient__c;
                   newCsir.add(csir);
                   system.debug('csir1 '+csir);
            }    
                    else if(recFlag == true && (cs.Category__c =='Product Deficiency' && cs.Complaint_Type__c == 'Treatment Complaints' 
                && cs.Complaint_Sub_Type__c =='Design Execution'&&cs.Root_Cause__c =='Features Placement')
                            &&(cListMonth.size()>=3||cListQuarter.size()>=3||cListPid.size()>=2))
            {
                system.debug('Scenario6');
                Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
                   csir.RecordTypeId = csirEarlyId;
                   csir.Ticket__c = cs.Id;
                   csir.Description__c = 'early alert system test';
                   csir.Status__c = 'In Progress';
                   csir.Ticket_Origin__c = 'Phone';
                   csir.Category__c = 'Product Deficiency';
                   csir.Complaint_type__c = 'Treatment Complaints';
                   csir.Complaint_Sub_Type__c = 'Design Execution';
                   csir.Root_Cause__c = 'Features Placement';
                csir.Trend_identified__c = '3 complaints per account in the same month';
                csir.Account__c = cs.AccountId;
                   csir.Region__c = cs.Region__c;
                   csir.Patient__c = cs.Patient__c;
                   newCsir.add(csir);
                   system.debug('csir1 '+csir);
            }    
            else if(recFlag == true && (cs.Category__c =='Non Valid' && cs.Complaint_Type__c == 'Non Valid' 
                && cs.Complaint_Sub_Type__c =='Anatomy/Geometry/Dentition Changes'&&cs.Root_Cause__c =='Fit Issues due to Relapse')
                    &&(cListMonth.size()>=4||cListQuarter.size()>=5||cListPid.size()>=2))
            {
                system.debug('Scenario 1');
                Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
                   csir.RecordTypeId = csirEarlyId;
                   csir.Ticket__c = cs.Id;
                   csir.Description__c = 'early alert system test';
                   csir.Status__c = 'In Progress';
                   csir.Ticket_Origin__c = 'Phone';
                   csir.Category__c = 'Non Valid';
                   csir.Complaint_type__c = 'Non Valid';
                   csir.Complaint_Sub_Type__c = 'Anatomy/Geometry/Dentition Changes';
                   csir.Root_Cause__c = 'Fit Issues due to Relapse';
                csir.Trend_identified__c = '2 complaints per account in the same month';
                csir.Account__c = cs.AccountId;
                   csir.Region__c = cs.Region__c;
                   csir.Patient__c = cs.Patient__c;
                   newCsir.add(csir);
                   system.debug('csir1 '+csir);
            }
        }
        insert newCsir;
    }
}

Test class
-----------------
public static testmethod void createTicket1test()
    {
        List<TriggerControl__c> lstTriggerControl = new list<TriggerControl__c>();
        lstTriggerControl.add(new TriggerControl__c(Name = 'ContactMasterTrigger',Active__c = true));
        insert lstTriggerControl;
        List<Case> cList = new List<Case>();
        List<Account> acList = new List<Account>();
        TestDataBuilder testBuilder = new TestDataBuilder();
        Account acc = new Account();
        acc = testBuilder.dummyAccount(1);
        acc.Business_Unit__c    = 'NA';
        acc.Payment_Terms__c = 'NT30';
        acc.Billing_Language__c = 'English';
        acc.Invoice_Preference__c = 'Email';
        database.insert(acc);
        acList.add(acc);
        Account acc1 = new Account();
        acc1 = testBuilder.dummyAccount(1);
        acc1.Business_Unit__c    = 'NA';
        acc1.Payment_Terms__c = 'NT30';
        acc1.Billing_Language__c = 'English';
        acc1.Invoice_Preference__c = 'Email';
        database.insert(acc1);
        acList.add(acc1);
        Account acc2 = new Account();
        acc2 = testBuilder.dummyAccount(1);
        acc2.Business_Unit__c    = 'NA';
        acc2.Payment_Terms__c = 'NT30';
        acc2.Billing_Language__c = 'English';
        acc2.Invoice_Preference__c = 'Email';
        database.insert(acc2);
        acList.add(acc2);
        Contact con = new Contact();
        con = testBuilder.dummyContact(1);
        //database.insert(con);
        List<Patient__c> pList = new List<Patient__c>();
        Patient__c pid = new Patient__c();
        pid.Name = 'test123';
        pid.Account__c = acc.Id;
        pid.Contact__c = con.Id;
        Database.insert(pid);
        pList.add(pid);
        Patient__c pid1 = new Patient__c();
        pid1.Name = 'test123';
        pid1.Account__c = acc.Id;
        pid1.Contact__c = con.Id;
        pList.add(pid1);
        Patient__c pid2 = new Patient__c();
        pid2.Name = 'test123';
        pid2.Account__c = acc.Id;
        pid2.Contact__c = con.Id;
        pList.add(pid2);
        Case caseinsrt = new Case();
        caseinsrt.Category__c  = 'Product Deficiency';
        caseinsrt.Complaint_Type__c='Aligner/retainer Fit Issues';
        caseinsrt.Complaint_Sub_Type__c = 'Case Related';
        caseinsrt.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
        caseinsrt.Status       ='closed';
        caseinsrt.Date_Complaint_Reported__c=Date.Today();
        caseinsrt.Sales_Order_Number__c='123456';
        caseinsrt.accountid    =acc.id;
        caseinsrt.caller_role__c='Sales Team';
        caseinsrt.consumer_advocacy_ticket__c = True;
        caseinsrt.CAM_Process_Completed__c = True;
       // caseinsrt.CAM_Opt_In__c = True;
        caseinsrt.Credit_Request_Category__c = 'Replacement';
        caseinsrt.RecordTypeId = eUiteroRecordTypeId;
        caseinsrt.Doctor_First_Name__c = 'Test';
        caseinsrt.Specific_Email__c ='test@test.com';       
        caseinsrt.ContactId = con.id;
        cList.add(caseinsrt);
        Database.insert(caseinsrt);
Customer_Support_Internal_Request__c csir = new Customer_Support_Internal_Request__c();
                   csir.RecordTypeId = csirEarlyId;
                   csir.Ticket__c = caseinsrt.Id;
                   csir.Description__c = 'early alert system test';
                   csir.Status__c = 'In Progress';
                   csir.Ticket_Origin__c = 'Phone';
                   csir.Category__c = 'Product Deficiency';
                   csir.Complaint_type__c = 'Aligner/retainer Fit Issues';
                   csir.Complaint_Sub_Type__c = 'Case Related';
                   csir.Root_Cause__c = 'Fit Issues due to Path of Insertion (whole arch)';
                   csir.Trend_identified__c = '4 complaints per account in the same month';
                   csir.Account__c = caseinsrt.AccountId;
                   csir.Region__c = caseinsrt.Region__c;
                   csir.Patient__c = caseinsrt.Patient__c;
        
           Database.insert(csir); 

Thanks!!
SwethaSwetha (Salesforce Developers) 
HI Jai,
The code provided in question does not highlight which lines of apex class are uncovered. The below articles give a good insight into how coverage can be improved
 
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines 

Code Coverage Best Practices
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_code_coverage_best_pract.htm
 
Checking Code Coverage
https://help.salesforce.com/articleView?id=code_dev_console_tests_coverage.htm&type=5
 
Deployment related code coverage issues
https://help.salesforce.com/articleView?id=000335222&type=1&mode=1
 
https://salesforce.stackexchange.com/questions/148894/help-required-to-get-full-code-covered-in-test-class

If this information helps, please mark the answer as best. Thank you