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
Darkangel8Darkangel8 

test class coverage is 69%

I need help in below apex class which display user details related to zipcode/account number. The code coverage is 69% help me with this-

Public list<UserDetails> getDetails(list<string> teriNames){
        set<id> teryIds = new set<id>();
        Map<id,Territory2> territorMap = new Map<id,Territory2>();
        Map<id,id> UserterriMap = new Map<id,id>();
        if(!teriNames.isEmpty()){
            
            for(Territory2 t:[SELECT id,DeveloperName,Name,Territory_No__c FROM Territory2 where Name IN : teriNames]){
               
                teryIds.add(t.id);
                territorMap.put(t.id,t);   
            }
        }
        set<Id> userIds = new set<id>();
        if(!teryIds.isEMpty()){
            for(UserTerritory2Association  Usert:[SELECT id,UserId,Territory2Id FROM UserTerritory2Association where isActive=true  and territory2id IN : teryIds ]){
                userIds.add(Usert.UserId );
                UserterriMap.put(Usert.UserId ,Usert.Territory2Id);
                  
            } 
        }
        if(!userIds.isEmpty()){
            
            for(user u:[select id, name ,phone,email, Manager.Name, Manager.Email, Manager.Phone, Business_Unit__c from user where id IN : userIds and isactive= true ORDER BY Business_Unit__c]){
                //users.add(u);
               
                UserDetails ud = new UserDetails();
                ud.usr = u;
                if(UserterriMap.containskey(u.id)){
                    Id terrritoryId = UserterriMap.get(u.id); 
                    ud.teriName =  territorMap.get(terrritoryId).name;
                }
                udetails.add(ud); 
            } 
        }
 return udetails;  
    }
    public class UserDetails{
        public user usr{get;set;}
        public string teriName{get;set;}
    }
}
CloudalyzeCloudalyze
Hi Dhanashree,
 
Could you please post the test class details and the screenshot of the current lines of codes covered?
Darkangel8Darkangel8
This is the test class i wrote to return list of users when we enter zipcode or account number-

@istest//(seeAllData =true)
public class TMReplookupversionconTest {
    
    static TestMethod void testSampleSearch(){
        // new account creation
        Account acc = new Account();
        acc.Name='test';
        acc.Account_No__c='5000000000';
        acc.billingpostalcode='54561';
        acc.Owner.name=u.Name;
             insert acc;
        // Account_Cross_Reference__c creation 
        Account_Cross_Reference__c acr = new Account_Cross_Reference__c();
        acr.Name = 'TestAcR';
        acr.SFDC_Account_ID__c = acc.id;
        acr.Source_ERP_System__c = 'ECCHQ';
        acr.ERP_Account_Number__c = '12345678';     
        acr.Enterprise_Account_Number__c ='5000000000';
        acr.ERP_System_Name__c = 'MEDI';
        insert acr;
        // new zip code creation 
   
        Zip_Code__c zipobj = new Zip_Code__c ();
        zipobj.name='54561';
        zipobj.BU__c='Diagnostics';
        zipobj.Country__c='us';
        zipobj.Territory_Code__c='123';
        zipobj.Territory_Name__c='Operative Care Consumables Inside Sales Southwest';
        
        insert zipobj;
      
        
        TMRRepLookupVersionCon myclass=new TMRRepLookupVersionCon();
        myclass.zips = new list<Zip_Code__c>();
        myclass.getSearchTypes();
        myclass.SearchType = 'zip';
        myclass.searchText = '54561';  
      /*  list<Zip_Code__c> zip = [select Territory_Name__c from Zip_Code__c where  Territory_Name__c ='Operative Care Consumables Inside Sales Southwest'];
        list<Territory> ter = [SELECT Id, name FROM Territory where Name =:zip[0].Territory_Name__c];
        list<userTerritory> uter =[select userid from userTerritory where id =:ter[0].id];
        list<user> u = [select id, name , email, phone from user where id =:uter[0].userid];*/
        myclass.search();           
        myclass.SearchType = 'act';
        myclass.searchText = '5000000000';        
        myclass.search();
         myclass.SearchType = 'act';
        myclass.searchText = '12345678';        
        myclass.search();
    } 
      static TestMethod void testSampleSearchErrorMs()
      {
        TMRRepLookupVersionCon myclass=new TMRRepLookupVersionCon();
        myclass.search();        
        myclass.SearchType = 'zip';
        myclass.search();
        
    }
}