• Darkangel8
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 9
    Replies
I am new to salesforce. Please help me to write the test class for below method-

public list<string> getZipCode( string  searchText ){
        list<string> teriNames = new list<string>();
        list<Zip_Code__c> ziplist = [Select Id, Name, BU__c, Country__c,Territory_Code__c, Territory_Name__c from Zip_Code__c where name =: searchText];
        for(Zip_Code__c zip : ziplist ){
            if(zip.Territory_Name__c != null){
                teriNames.add(zip.Territory_Name__c);  
                
            }
        }        
        
        return teriNames ;
    }
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;}
    }
}
Want to create a batch class on contact object having lookup with account. When contact mobile number get updated then latest mobile umber will get reflected in account object. Please help to code this.
I am new to salesforce. Please help me to write the test class for below method-

public list<string> getZipCode( string  searchText ){
        list<string> teriNames = new list<string>();
        list<Zip_Code__c> ziplist = [Select Id, Name, BU__c, Country__c,Territory_Code__c, Territory_Name__c from Zip_Code__c where name =: searchText];
        for(Zip_Code__c zip : ziplist ){
            if(zip.Territory_Name__c != null){
                teriNames.add(zip.Territory_Name__c);  
                
            }
        }        
        
        return teriNames ;
    }
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;}
    }
}
Want to create a batch class on contact object having lookup with account. When contact mobile number get updated then latest mobile umber will get reflected in account object. Please help to code this.