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
Padmini S 26Padmini S 26 

how to increase apex trigger code coverage in test class


Below is the apex trigger which i have written. But i got only 64% code coverage. I am not getting how to increase code coverage. Please help me how to increase code coverage.
trigger LeadTrigger on Lead (before insert,before update, after update) 
    Map<String, String> dispositionMap = new Map<String, String>();
    Map<String, DateTime> dispositionDateTimeMap = new Map<String, DateTime>();
    List<Id> leadIds = new List<Id>();
        leadCategorizationClass.leadCategorization(,Trigger.oldMap);       //Lead Categorization
        LeadHelperClass.AddNewLead(Trigger.New);         //NEW LEAD
        leadAllocationClass.leadAllocation(Trigger.New); //GO TO CSO
        leadReAllocationClass.setRMLeadOpptyInfo(Trigger.New, Trigger.oldMap);        //When RM is Assigned
    else if(Trigger.isUpdate && Trigger.isBefore)
       leadCategorizationClass.leadCategorization(,Trigger.oldMap);       //Lead Categorization
            leadReAllocationClass.leadAllocationFromQueue(Trigger.New,Trigger.oldMap);//CSO allocation for Queue.
            leadReAllocationClass.setRMLeadOpptyInfo(Trigger.New, Trigger.oldMap);    //When RM is Assigned
        for(lead ld:
                && (ld.Dispositions__c=='Appointment Fixed' || 
                    ld.Dispositions__c=='Follow Up' || 
                        ld.Dispositions__c=='Engaged' || ld.Dispositions__c=='Number was busy' || 
                        ld.Dispositions__c=='Ringing Not Responding' || ld.Dispositions__c=='Not available'))
                if(ld.Dispositions__c=='Appointment Fixed')
                    dispositionDateTimeMap.put(ld.Dispositions__c, ld.Appointment_Creation_Date__c);
                else if(ld.Dispositions__c=='Follow Up')
                    dispositionDateTimeMap.put(ld.Dispositions__c, ld.Prefered_Date_Time__c);
           ld.Email_Internal__c = ld.Email;
            // call method helper class
            LeadHelperClass.sendingSMS(dispositionMap, dispositionDateTimeMap);
    else if(Trigger.isUpdate && Trigger.isAfter)
        // for FarEye Integration //
        system.debug('After Update Trigger Fired');
        for(lead ld: Trigger.New)
            if(((ld.Dispositions__c!=trigger.oldMap.get( && (ld.Dispositions__c=='Appointment Fixed') && 
               (ld.RM__c!=null)) || (ld.Resend_To_FarEye__c==true)    
                system.debug('Class Calling');
                //system.debug('Class End of Calling');
        system.debug('IDS: '+leadIds.size());
            // call batch class here
            system.debug('<<<<<<<<<< Batch Called After Update');
            Database.executeBatch(new BatchClassFarEyeIntegrationLead(leadIds)) ;

Below is the test class.
public class TestLeadHelperClass {
 Public static testmethod void testLeadHelper()
     Campaign cp = new Campaign(Name='test', IsActive=true, Interested_Product__c='LI', Channel__c='Retail');
     insert cp;
     Lead L1 = new Lead(FirstName='Harsh',LastName='Test',Email= '', Status='CSOAllocated',Company = 'Test Name', Remarks__c= 'good',Client_Type__c='NRI',Postal_Code__c='474001',Tax_Bracket__c='5%',Disposition_Category__c='General', Dispositions__c='Appointment Fixed', Interested_Product__c='Mutual Fund',Mobile_Number__c='9669259232', Appointment_Creation_Date__c = System.Today(), Campaigns__c=;
     insert L1;
     List<Lead> LT = new List<Lead>();
     Lead l = [SELECT Id, FirstName,LastName,Email,Status,Company ,Remarks__c,Client_Type__c,Postal_Code__c,Tax_Bracket__c,Disposition_Category__c,Dispositions__c,Interested_Product__c,Mobile_Number__c,Campaigns__c FROM Lead WHERE Id = :LT[0].Id];

     l.FirstName= 'Test Account 2';
     update l;
     Account acc = new Account(Name ='Testing', Client_Code_KYC__c='newsourcecode');
     insert acc;
     Opportunity opp1 = new Opportunity( Name = 'mAWS Usage', StageName = 'Negotiations', CloseDate =,Email__c='', Client_Type__c='Individual', AccountId=acc.Id);
     insert opp1;
     Task t = new task(WhatID =,Subject='Donni',Status='New',Priority='Normal');
     insert t;
      SMSSetings__c sms = new SMSSetings__c(Disposition_Name__c = 'testsms',SMS_Content__c = 'testsms content' );
     Map<String, String> dispositionMap = new  Map<String, String>{'test'=>'test1'};
      DateTime dat = datetime.newInstance(2014, 9, 15, 12, 30, 0);
     Map<String, DateTime> dispositionDateTimeMap= new  Map<String, DateTime>{'test'=>dat};  
     LeadHelperClass lc = new LeadHelperClass();
Thanks in Advance.
Wilfredo Morillo 20Wilfredo Morillo 20
This test class is for the trigger or this is a master trigger for lead?
if this is a master trigger and the test class is intended to run just part of it you need to run all other test clases to get more cover.