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
PSahuPSahu 

Write test class for my controller class

global with sharing class multiweatherController {  
     
     public Multi_Weather__c data{get; set;}

    public boolean detailsinfo;
    public boolean editform;
    public boolean full_metro_render;
    public boolean metro_render;
    public Multi_Weather__c MW;
    public Multi_Weather__c multi_weather{get;set;}
    public string Wk_weather_theme;
    public String Wk_Weather_Theme_Class;
    public String[] Wk_City_code;
    public string result = '';
    public string[] Wk_city;
    public string leadid;
    public String[] lead;
    public string accountid;
    public String[] account;
    public string contactid;
    public String[] contract;
    public string contractid;
    public String[] contact;
    private ApexPages.StandardController ctrl;        

     public multiweatherController() {       
            
         List<Multi_Weather__c> mwList = [
           SELECT Id FROM Multi_Weather__c];
        
        if(mwList.size()!=0)
        {   
        multi_weather = [SELECT Id, name, Width__c, City_Code__c, Weather_Theme__c, Theme_Background_Color__c, Metro_Text_color__c, Show_Next_Days__c, Temp_Unit__c, High_Low_Temp__c, Wind_Speed__c, Humidity__c, Show_Country__c, Visibility__c, Show_Sunrise__c, Show_Sunset__c FROM Multi_Weather__c];
        ApexPages.currentPage().getParameters().put('Id', multi_weather.id);
        }         
              }
              
           public string getcontractid()
        {
           //leadid = apexpages.currentpage().getparameters().get('sfdcIFrameOrigin');   
           contractid = ApexPages.currentPage().getHeaders().get('referer');
            
           contract = contractid.split('/');
           
            try {
            
            List<Contract> contractdata = [Select Id, BillingCity from Contract Where Id =:contract[3]];
                        
              return contractdata.get(0).BillingCity;       
              
            }
            Catch (exception e) {
           
              return null;
            }       
          
        } 
        
         public string getcontactid()
        {
           //leadid = apexpages.currentpage().getparameters().get('sfdcIFrameOrigin');   
           contactid = ApexPages.currentPage().getHeaders().get('referer');
            
           contact = contactid.split('/');
           
            try {
            
            List<Contact> contactdata = [Select Id, MailingCity from Contact Where Id =:contact[3]];
                        
              return contactdata.get(0).MailingCity;       
              
            }
            Catch (exception e) {
           
              return null;
            }       
          
        } 
              
         public string getaccountid()
        {
           //leadid = apexpages.currentpage().getparameters().get('sfdcIFrameOrigin');   
           accountid = ApexPages.currentPage().getHeaders().get('referer');
            
           account = accountid.split('/');
           
            try {
            
            List<Account> accountdata = [Select Id, BillingCity from Account Where Id =:account[3]];
                        
              return accountdata.get(0).BillingCity;       
              
            }
            Catch (exception e) {
           
              return null;
            }       
          
        }           
              
        public string getleadid()
        {
           //leadid = apexpages.currentpage().getparameters().get('sfdcIFrameOrigin');   
           leadid = ApexPages.currentPage().getHeaders().get('referer');
            
           lead = leadid.split('/');
           
            try {
            
            List<Lead> leaddata = [Select Id, City from Lead Where Id =:lead[3]];
                        
              return leaddata.get(0).City;       
              
            }
            Catch (exception e) {
           
              return null;
            }       
          
        }     
              
         public string getWoeid()
            {
            
            if(getleadid() != null)
            {
                Http http =new Http();
                HttpRequest req =new HttpRequest();
                  req.setEndpoint('http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%281%29%20where%20text=%22'+getleadid()+',%20il%22&format=json');
                req.setmethod('GET');
                HttpResponse res = http.send(req);
                String str = res.getbody();
                Woeid_JSON2Woeid_Apex wk_woeid = Woeid_JSON2Woeid_Apex.parse(str);   
            
                result  = '"'+wk_woeid.query.Results.Place.woeid +'"';
            } else if(getaccountid() != null)
            {
                Http http =new Http();
                HttpRequest req =new HttpRequest();
                  req.setEndpoint('http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%281%29%20where%20text=%22'+getaccountid()+',%20il%22&format=json');
                req.setmethod('GET');
                HttpResponse res = http.send(req);
                String str = res.getbody();
                Woeid_JSON2Woeid_Apex wk_woeid = Woeid_JSON2Woeid_Apex.parse(str); 
                result  = '"'+wk_woeid.query.Results.Place.woeid +'"';  
            
            } else if(getcontactid() != null)
            {
                 Http http =new Http();
                HttpRequest req =new HttpRequest();
                  req.setEndpoint('http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%281%29%20where%20text=%22'+getcontactid()+',%20il%22&format=json');
                req.setmethod('GET');
                HttpResponse res = http.send(req);
                String str = res.getbody();
                Woeid_JSON2Woeid_Apex wk_woeid = Woeid_JSON2Woeid_Apex.parse(str); 
                result  = '"'+wk_woeid.query.Results.Place.woeid +'"';  
            
            } else if(getcontractid() !=null)
            {
                  Http http =new Http();
                HttpRequest req =new HttpRequest();
                  req.setEndpoint('http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%281%29%20where%20text=%22'+getcontractid()+',%20il%22&format=json');
                req.setmethod('GET');
                HttpResponse res = http.send(req);
                String str = res.getbody();
                Woeid_JSON2Woeid_Apex wk_woeid = Woeid_JSON2Woeid_Apex.parse(str); 
                result  = '"'+wk_woeid.query.Results.Place.woeid +'"';  
            }
            else {
                List<String> Wk_city = multi_weather.City_Code__c.split(',');   
                
            for(integer i=0; i<Wk_city.size(); i++){
                
                Http http =new Http();
                HttpRequest req =new HttpRequest();
  
                 req.setEndpoint('http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%281%29%20where%20text=%22'+Wk_city[i]+',%20il%22&format=json');
             
               
                req.setmethod('GET');
                HttpResponse res = http.send(req);
                String str = res.getbody();
                Woeid_JSON2Woeid_Apex wk_woeid = Woeid_JSON2Woeid_Apex.parse(str);   
            
                result  = '"'+wk_woeid.query.Results.Place.woeid +'"'+ ',' + result;
                
                }
                 //result = Wk_city[i] + i + result;
                
            }              
            
              return result;          
            
            
            }     
              
         public boolean getfull_metro_render(){

            if(multi_weather.Weather_Theme__c == 'Full Metro')
             {
                 //metro_render = true;
                 full_metro_render = true;
                
             } else 
             {
                   //metro_render = false;
                 full_metro_render = false;
             }
            return full_metro_render;
            }     
              
        public boolean getmetro_render(){
         if(multi_weather.Weather_Theme__c != 'Full Metro')
         {
             metro_render = true;
             //full_metro_render = true;
            
         } else 
         {
               metro_render = false;
            // full_metro_render = false;
         }
        return metro_render;
        }   
        
        public string getWk_Country_code(){

        if (multi_weather.Weather_Theme__c == 'Metro' || multi_weather.Weather_Theme__c == 'Full Metro') {
            Wk_City_code = getWoeid().split(',');
            return Wk_City_code[0];    
        } else {
        
            return getWoeid();
        
        }          

        }   
        
        public string getWk_Tempunit(){

        if(multi_weather.Temp_Unit__c == 'Celsisus')
        {
            multi_weather.Temp_Unit__c = 'c';
        } else
        {
            multi_weather.Temp_Unit__c = 'f';
        }
        return multi_weather.Temp_Unit__c;
        }
        
        public string getWk_weather_func(){

         if(multi_weather.Weather_Theme__c == 'Metro')
         {
             
             Wk_weather_theme = 'weatherfeedmetro';
         } else 
         {
             Wk_weather_theme = 'weatherfeed';
         }
            return Wk_weather_theme;
        }
        
        public string getWk_Weather_Theme(){

        if (multi_weather.Weather_Theme__c == 'Dark') {
            Wk_Weather_Theme_Class = 'vertical_dark';
        } else if (multi_weather.Weather_Theme__c == 'Full Metro') {
            Wk_Weather_Theme_Class = 'vertical_full_metro';
        } else if (multi_weather.Weather_Theme__c == 'Light') {
            Wk_Weather_Theme_Class = 'vertical_light';
        } else if (multi_weather.Weather_Theme__c == 'Metro') {
            Wk_Weather_Theme_Class = 'vertical_metro';
        } else if (multi_weather.Weather_Theme__c == 'Simple Dark') {
            Wk_Weather_Theme_Class = 'vertical_simple_dark';
        } else if (multi_weather.Weather_Theme__c == 'Simple Light') {
            Wk_Weather_Theme_Class = 'vertical_simple_light';
        }
        
            return multi_weather.Weather_Theme__c;
        }
        
        public string getWk_main_content(){
 
         string Weather_Theme = getWk_Weather_Theme();
         string content;
         
         if(multi_weather.Weather_Theme__c == 'Metro' || multi_weather.Weather_Theme__c == 'Full Metro')
         {
              content = '<div id="wkweath_item" class="'+Wk_Weather_Theme_Class+'"; style="height:auto; display:inline-block; width:'+multi_weather.Width__c+'px; background: none repeat scroll 0 0 '+multi_weather.Theme_Background_Color__c+' " > </div>';
          
         } else
         {
              
            content = '<div style="width:'+multi_weather.Width__c+'px;"><div class="wk_scroll" ><div id="wkweath_item" class="'+Wk_Weather_Theme_Class+' items"; style="width:'+multi_weather.Width__c+'px;"></div></div><div class="navi"></div></div>';
         }
         
            return content;
        }
        

}
Please tell me how to write the test class for my controller class for alteast 75% code coverage.

Thanks in advance
PSahuPSahu
Any Updates?