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
MaheemSamMaheemSam 

Lead test class is not covering the list

Hi, 

  For Class   
public class LeadTriggerUtils {
    
    public static void processLeadOnUpdate(Map<id, Lead> newMap, Map<id, Lead> oldMap) { 
        List<Lead> leadLst = new List<Lead>();
        for (Lead lead : newMap.values()) {
            Lead oldLead = oldMap.get(lead.id);
            if(lead.rvpe__IsDealRegistration__c && lead.rvpe__RVAccount__c != null && lead.rvpe__RVAccount__c != oldLead.rvpe__RVAccount__c) {
        leadLst.add(lead);
            }
        }
        if(!leadLst.isEmpty()) {
      processChangeOwnerAsPartnerAccount(leadLst); 
        }
    }
    
    public static void processLeadOnInsert(List<Lead> newLst) {
      processChangeOwnerAsPartnerAccount(newLst);
    }
    public static void processChangeOwnerAsPartnerAccount(List<Lead> newLst) {
        List<ID> rvAcctIDs = new List<ID>();
        for(Lead lead : newLst) {
            if(lead.rvpe__IsDealRegistration__c && (lead.Global_Region__c == 'EMEA' || lead.Global_Region__c == 'LATAM') && lead.rvpe__RVAccount__c != null) {
                rvAcctIds.add(lead.rvpe__RVAccount__c);
            }
        }
        Map<ID, rvpe__RVAccount__c> rvActMap = new Map<Id, rvpe__RVAccount__c>([select id, rvpe__SFAccount__c, rvpe__SFAccount__r.OwnerId from rvpe__RVAccount__c where id in :rvAcctIDs]);
        for(Lead lead : newLst) {
            rvpe__RVAccount__c rvAct = rvActMap.get(lead.rvpe__RVAccount__c);
            if(rvAct != null && rvAct.rvpe__SFAccount__c != null) {
                lead.OwnerId = rvAct.rvpe__SFAccount__r.OwnerId;
            }
        }
    }
}

Below is the test class it has 90% code coverage. 
@isTest(seealldata = true)
public class LeadTriggerUtilsTest{
    @istest
        public static void leadTest(){
        
          rvpe__RVAccount__c rpv = [select id from rvpe__RVAccount__c where rvpe__SFAccount__c <> null and rvpe__PartnerLevel__c = 'NA Reseller' limit 1];
        
            Lead l1 = new Lead();
            l1.FirstName = 'Pranavan';
            l1.LastName = 'Karthi';
            l1.Email = 'karthi@pranavan.com';
            l1.Company = 'Pranavan';
            l1.country = 'United States';
            l1.rvpe__IsDealRegistration__c = true;
            l1.Global_Region__c = 'EMEA'; 
            l1.rvpe__RVAccount__c = rpv.id;
            
            insert l1;
            
            l1.FirstName = 'Velu';
            
            update l1;
            
       }
       
       public static void leadTest_two(){
       
        Lead l = [select id from lead where rvpe__IsDealRegistration__c  = true and Global_Region__c  <> null and rvpe__RVAccount__c  <> null limit 1];
        
        l.firstname = 'sudhir';
        
        update l;
  
        
       }
}
Only below lines are not covered. 
User-added image
 
When I try to deploy in production it is giving code coverage error.  Please suggest me how to fix. 

Thanks
GMASJ
$hwet@$hwet@
Hi ,

It is not going inside the IF condition because the below condition is not satisfied.
lead.rvpe__RVAccount__c != oldLead.rvpe__RVAccount__c

both the accounts in oldmap and trigger.new is same.
 
MaheemSamMaheemSam
Thanks for your reply i have 90% code coverage do you know why I keep getting code coverage when i try to validate in production.
Ajay K DubediAjay K Dubedi
Hi  MaheemSam,

Have a look at this thread :
https://developer.salesforce.com/forums/?id=906F0000000AeAeIAK

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi