+ Start a Discussion
GMASJGMASJ 

While deploying in production show 0% code coverage

Hi, 

  Code coverage for below class is 90% in sandbox. 
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;
            }
        }
    }
}

Test Class
@isTest(seealldata=true)
public class LeadTriggerUtilsTest
{
    
    public static testMethod void Method1(){
        
           
          rvpe__RVAccount__c rpv = [select id from rvpe__RVAccount__c where rvpe__SFAccount__c <> null and rvpe__PartnerLevel__c = 'NA Reseller' limit 1];
          rvpe__RVAccount__c rpv2 = [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';
            l1.rvpe__RVAccount__c = rpv2.id;
            
            update l1;
            
       }
}

When I try to validate the change set in production it shows 0% code coverage. Please suggest me what is the issue here in test class

Thanks
Sudhir​​​​​​​
PrincyPrincy

Hi Sudhir,
A few things you could check:
1. You have not posted the trigger. Is it part of the deployment? If yes, are the methods called on proper insert and update events?
2. Is it just the code coverage error or test class failure. Line no 8 and 9 have potential risks of failure for the reason of list has no rows of assignment.
3. Is your profile same in the sandbox and production? Check the sharing settings on rvpe__RVAccount__c and rvpe__RVAccount__c object?

Irrespective of the issue, using @seeAllData=true is not a good practice. 

GMASJGMASJ
Thanks Princy for your responce. I have same profile in sandbox and production.  Here are my responce for you questions. 

1. You have not posted the trigger. Is it part of the deployment? If yes, are the methods called on proper insert and update events?
          Trigger already exist so I am not moving the trigger in changeset it is just the class. 
2. Is it just the code coverage error or test class failure. Line no 8 and 9 have potential risks of failure for the reason of list has no rows of assignment.
         It is giving just the code coverage error not a test class faiure also I tried to deploy other test class it got deployed without any issue. 
3. Is your profile same in the sandbox and production? Check the sharing settings on rvpe__RVAccount__c and rvpe__RVAccount__c object?
Irrespective of the issue, using @seeAllData=true is not a good practice. 
        Profile and object viisbility is same in both sandbox and production. 
       
Please let me know is there any other issue which is causing this code coverage issue. 

Thanks
Sudhir
PrincyPrincy

Hey Sudhir, what I meant to ask is could you check if processLeadOnInsert and processLeadOnUpdate are called from the trigger in production? Also, please check if the trigger is Active in prod.