• PSahu
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 12
    Replies
How to add a record of custom object on the installation of package i am trying in controller but it says DML not allowed
  • August 21, 2015
  • Like
  • 0
//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

public class Woeid_JSON2Woeid_Apex {

    public class Place {
        public String woeid;
    }

    public class Query {
        public Integer count;
        public String created;
        public String lang;
        public Results results;
    }

    public Query query;

    public class Results {
        public Place place;
    }

    
    public static Woeid_JSON2Woeid_Apex parse(String json) {
        return (Woeid_JSON2Woeid_Apex) System.JSON.deserialize(json, Woeid_JSON2Woeid_Apex.class);
    }

   
}
I am new in apex please tell me how to write test class for 100% code coverage and how to write it's test cases to debug and check our code is 100% correct working.
  • August 07, 2015
  • Like
  • 0
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
  • August 07, 2015
  • Like
  • 0
public class MultiWeatherExtension {

    public MultiWeatherExtension() {

    }

public Multi_Weather__c data{get; set;}
//public Id id;
public boolean detailsinfo;
public boolean editform;

public Multi_Weather__c MW;
public Multi_Weather__c multi_weather{get;set;}

public string result = '';


public MultiWeatherExtension(ApexPages.StandardController stdController) {
 

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);
}
data=(Multi_Weather__c)stdcontroller.getrecord();

detailsinfo=true;
editform=false;

}


public boolean getdetailsinfo(){
return detailsinfo;
}
public boolean geteditform(){
return editform;
}

public pagereference save(){
detailsinfo=false;
editform=false;

//id=apexpages.currentpage().getparameters().get('id');

List<Multi_Weather__c> mwList = [
   SELECT Id FROM Multi_Weather__c];

//System.debug('myList size: ' + myList.size());    

if(mwList.size()==0)
{
insert data;
//id=data.id;
PageReference Multi_Weather = Page.Multi_Weather;
Multi_Weather.setRedirect(true);
//Multi_Weather.getParameters().put('id',data.id);
return Multi_Weather;
} else
{
MW = [SELECT Id FROM Multi_Weather__c];
data.id = MW.id;
update data;
PageReference Multi_Weather = Page.Multi_Weather;
Multi_Weather.setRedirect(true);
//Multi_Weather.getParameters().put('id',MW.id);
return Multi_Weather;

}
return null;
}

public pagereference editdata(){
detailsinfo=false;
editform=true;

return null;


}

}
Hello to all i am new in apex please help me for writing the test class for 100% code coverage
  • August 07, 2015
  • Like
  • 0
I am new in apex and salesforce please tell me how to write test class of a class in which value in method get by current page url my class is given below please reply me

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

   
    public String[] contract;
    public string contractid;

    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 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;
            }       
          
        }
              
       

}

Thanks in advance
  • August 06, 2015
  • Like
  • 0
I am working on an application in salesforce for this i have write 3 classes and it's 3 test class but when i was go to make its package it's give me error of code coverage of 5% atleast 75 % required after that  i was checkmy test class but i am unable understand the issue. below is one of my class with its test class and it's code coverage is 0 Please check it


public class Woeid_JSON2Woeid_Apex {     
public class Place {         
public String woeid;     
}     
public class Query {        
 public Integer count;         
public String created;         
public String lang;         
public Results results;     
}     
public Query query;     
public class Results {         
public Place place;     
}          
public static Woeid_JSON2Woeid_Apex parse(String json) {         return (Woeid_JSON2Woeid_Apex) System.JSON.deserialize(json, Woeid_JSON2Woeid_Apex.class);    
 }    
}
and it's test class

@isTest
private class Woeid_JSON2Woeid_ApexTest {
public static Woeid_JSON2Woeid_Apex parse(String json) {
        return (Woeid_JSON2Woeid_Apex) System.JSON.deserialize(json, Woeid_JSON2Woeid_Apex.class);
    }
   static testMethod void testParse() {
        String json = '{\"query\":{\"count\":1,\"created\":\"2015-08-05T10:25:32Z\",\"lang\":\"en-US\",\"results\":{\"place\":{\"woeid\":\"2390809\"}}}}';
        Woeid_JSON2Woeid_Apex obj = parse(json);
        //System.assert(obj != null);
    }   

}

Please reply me.
  • August 06, 2015
  • Like
  • 0
hello ,
Please check my snopshot for more description http://awesomescreenshot.com/070543dx79 i want to fetch lead city name and pass to my custom controller method on page load of lead record i.e if lead city name is mumbai then my visual force page which is located in left sidebar also show mumbai.

Thanks in advance
  • July 31, 2015
  • Like
  • 0
suppose this is my  vf page https://c.ap2.visual.force.com/apex/multi_weather and in want to autopopulate the Form value i.e when the page is load the one read that i was insert in it before the record value is autopopulated in it without passing id in the url.
i am new in apex and visual form my aim is to make a setting page in which the page accept values at first time and when the second time user go to the url https://c.ap2.visual.force.com/apex/multi_weather the saved value will be autopopulated

Thanks
  • July 24, 2015
  • Like
  • 0
For example if i want to get news feed from facebook by graph api and apend these JSON data feed into the div by visualforce pages then how is it possible please explain the procedure i am new in salesforce and apex

I am done this task in php demo link :- http://joomla25.webkul.com/facebook-display/facebook-wall-feed.html

We want make a aap in salesforce like this.
  • June 25, 2015
  • Like
  • 1
For example if i want to get news feed from facebook by graph api and apend these JSON data feed into the div by visualforce pages then how is it possible please explain the procedure i am new in salesforce and apex

I am done this task in php demo link :- http://joomla25.webkul.com/facebook-display/facebook-wall-feed.html

We want make a aap in salesforce like this.
  • June 25, 2015
  • Like
  • 1
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
  • August 07, 2015
  • Like
  • 0
public class MultiWeatherExtension {

    public MultiWeatherExtension() {

    }

public Multi_Weather__c data{get; set;}
//public Id id;
public boolean detailsinfo;
public boolean editform;

public Multi_Weather__c MW;
public Multi_Weather__c multi_weather{get;set;}

public string result = '';


public MultiWeatherExtension(ApexPages.StandardController stdController) {
 

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);
}
data=(Multi_Weather__c)stdcontroller.getrecord();

detailsinfo=true;
editform=false;

}


public boolean getdetailsinfo(){
return detailsinfo;
}
public boolean geteditform(){
return editform;
}

public pagereference save(){
detailsinfo=false;
editform=false;

//id=apexpages.currentpage().getparameters().get('id');

List<Multi_Weather__c> mwList = [
   SELECT Id FROM Multi_Weather__c];

//System.debug('myList size: ' + myList.size());    

if(mwList.size()==0)
{
insert data;
//id=data.id;
PageReference Multi_Weather = Page.Multi_Weather;
Multi_Weather.setRedirect(true);
//Multi_Weather.getParameters().put('id',data.id);
return Multi_Weather;
} else
{
MW = [SELECT Id FROM Multi_Weather__c];
data.id = MW.id;
update data;
PageReference Multi_Weather = Page.Multi_Weather;
Multi_Weather.setRedirect(true);
//Multi_Weather.getParameters().put('id',MW.id);
return Multi_Weather;

}
return null;
}

public pagereference editdata(){
detailsinfo=false;
editform=true;

return null;


}

}
Hello to all i am new in apex please help me for writing the test class for 100% code coverage
  • August 07, 2015
  • Like
  • 0
I am new in apex and salesforce please tell me how to write test class of a class in which value in method get by current page url my class is given below please reply me

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

   
    public String[] contract;
    public string contractid;

    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 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;
            }       
          
        }
              
       

}

Thanks in advance
  • August 06, 2015
  • Like
  • 0
I am working on an application in salesforce for this i have write 3 classes and it's 3 test class but when i was go to make its package it's give me error of code coverage of 5% atleast 75 % required after that  i was checkmy test class but i am unable understand the issue. below is one of my class with its test class and it's code coverage is 0 Please check it


public class Woeid_JSON2Woeid_Apex {     
public class Place {         
public String woeid;     
}     
public class Query {        
 public Integer count;         
public String created;         
public String lang;         
public Results results;     
}     
public Query query;     
public class Results {         
public Place place;     
}          
public static Woeid_JSON2Woeid_Apex parse(String json) {         return (Woeid_JSON2Woeid_Apex) System.JSON.deserialize(json, Woeid_JSON2Woeid_Apex.class);    
 }    
}
and it's test class

@isTest
private class Woeid_JSON2Woeid_ApexTest {
public static Woeid_JSON2Woeid_Apex parse(String json) {
        return (Woeid_JSON2Woeid_Apex) System.JSON.deserialize(json, Woeid_JSON2Woeid_Apex.class);
    }
   static testMethod void testParse() {
        String json = '{\"query\":{\"count\":1,\"created\":\"2015-08-05T10:25:32Z\",\"lang\":\"en-US\",\"results\":{\"place\":{\"woeid\":\"2390809\"}}}}';
        Woeid_JSON2Woeid_Apex obj = parse(json);
        //System.assert(obj != null);
    }   

}

Please reply me.
  • August 06, 2015
  • Like
  • 0
hello ,
Please check my snopshot for more description http://awesomescreenshot.com/070543dx79 i want to fetch lead city name and pass to my custom controller method on page load of lead record i.e if lead city name is mumbai then my visual force page which is located in left sidebar also show mumbai.

Thanks in advance
  • July 31, 2015
  • Like
  • 0
For example if i want to get news feed from facebook by graph api and apend these JSON data feed into the div by visualforce pages then how is it possible please explain the procedure i am new in salesforce and apex

I am done this task in php demo link :- http://joomla25.webkul.com/facebook-display/facebook-wall-feed.html

We want make a aap in salesforce like this.
  • June 25, 2015
  • Like
  • 1
Hi,

I have 3 http callouts in batch - execute method, i am writting test class for batch class. I have created Mock test class.
Problem is: i can able to cover first callout, but not 2nd and 3rd callout
Please tell me how many callouts we can test from test class, please advise me how can i do this