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
Navya sree 4Navya sree 4 

Customer rating test class Help?

Hi,
Can you please help me with test class


public class OV_CustomerTierCtrl {
    //To get ultimate parent customer tier,Total leasearea for current account 
    @AuraEnabled public static OV_CustomerTierWrapper getCustomerTier(String id){
        OV_CustomerTierWrapper dbw = new OV_CustomerTierWrapper();
        Account acc = [Select Ultimate_Parent_Account_ID_t__c from Account where Id =:id];
        getLeaseArea(id,dbw,'Local');
        addCustomerTier(dbw.totalLeaseSQFT,'Local',dbw); 
        getLeaseArea(acc.Ultimate_Parent_Account_ID_t__c,dbw,'Global');
        addCustomerTier(dbw.totalUltimateLeaseSQFT,'Global',dbw);
        return dbw;        
    }
    //To get total lease area for entire hirarchy
    private static void getLeaseArea(String id , OV_CustomerTierWrapper dbw,String tierType){
        String acctIds =OV_BAUtility.getAcctIds(id);   
        String leaseSQFTQuery = 'select sum(Lease_Area_SF__c) from Lease__c where isActive__c= \'yes\' AND Account_Name__r.Id IN '+acctIds;
        Decimal leaseSQFT=0;
        try{   
            AggregateResult[] acct = database.query(leaseSQFTQuery);
            if(acct[0].get('expr0')!=null){
                leaseSQFT = (Decimal)acct[0].get('expr0');
            } 
            if(tierType=='Global'){
                dbw.totalUltimateLeaseSQFT=leaseSQFT;
            }else{
                dbw.totalLeaseSQFT=leaseSQFT;
            }    
        }catch(Exception e){
        }        
    }
    //To update ultimate parent customer tier based on total lease area 
    private static void addCustomerTier(Decimal leaseArea,String tierType,OV_CustomerTierWrapper dbw ){
        String customerTier='';
        CustomerTier__c tier =[SELECT Bronze_Level__c,Gold_Level__c,Platinum_Level__c,Silver_Level__c FROM CustomerTier__c];
        if(leaseArea < tier.Bronze_Level__c){
            customerTier='Bronze'; 
        }else if(leaseArea>=tier.Bronze_Level__c && leaseArea<tier.Silver_Level__c){
            customerTier='Silver'; 
        }else if(leaseArea>=tier.Silver_Level__c && leaseArea<tier.Gold_Level__c){
            customerTier='Gold'; 
        }else{
            customerTier='Platinum';  
        }
        if(tierType=='Global'){
            dbw.globalUltimateTier=customerTier;
        }else{
            dbw.customerTier=customerTier;
        }        
    }
    public class OV_CustomerTierWrapper{
        @AuraEnabled public Decimal totalLeaseSQFT{get;set;}
        @AuraEnabled public Decimal totalUltimateLeaseSQFT{get;set;}
        @AuraEnabled public String customerTier{get;set;}
        @AuraEnabled public String globalUltimateTier{get;set;}
    }
}
sfdcMonkey.comsfdcMonkey.com
try something like this : this will give you more then 75% code coverge 
@isTest
public class oV_Test {
    static testMethod void testMethodOne() {
        account parentAcc = new account();
         parentAcc.Name = 'parent Acc';
        // add all account required fields here 
        insert parentAcc;
        
        account acc = new account();
         acc.Name = 'test acc';
        acc.Ultimate_Parent_Account_ID_t__c = parentAcc.id;
        // add all account required fields here 
        insert acc;
        
        CustomerTier__c oCT = new CustomerTier__c();
        oCT.Bronze_Level__c = 10;
        oCT.Gold_Level__c = 5;
        oCT.Platinum_Level__c = 15;
        oCT.Silver_Level__c = 20;
        // add all CustomerTier__c required fields here 
        insert oCT;
        
        Lease__c oLease = new Lease__c();
          oLease.isActive__c = 'yes';
          oLease.Account_Name__c = parentAcc.Id;
        // add all Lease__c required fields here 
        insert  oLease;
        
       OV_CustomerTierCtrl.getCustomerTier(acc.Id);     
        
    }

}

Thanks let us know if it helps you