Skip to main content
Hi

I wrote One soap class i checked developer consloe its displyed country and state values .

//Generated by wsdl2apex

public class GlobalWhetherClass {

    public class GetWeather_element {

        public String CityName;

        public String CountryName;

        private String[] CityName_type_info = new String[]{'CityName','http://www.webserviceX.NET',null,'0','1','false'};

        private String[] CountryName_type_info = new String[]{'CountryName','http://www.webserviceX.NET',null,'0','1','false'};

        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};

        private String[] field_order_type_info = new String[]{'CityName','CountryName'};

    }

    public class GetCitiesByCountry_element {

        public String CountryName;

        private String[] CountryName_type_info = new String[]{'CountryName','http://www.webserviceX.NET',null,'0','1','false'};

        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};

        private String[] field_order_type_info = new String[]{'CountryName'};

    }

    public class GetWeatherResponse_element {

        public String GetWeatherResult;

        private String[] GetWeatherResult_type_info = new String[]{'GetWeatherResult','http://www.webserviceX.NET',null,'0','1','false'};

        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};

        private String[] field_order_type_info = new String[]{'GetWeatherResult'};

    }

    public class GetCitiesByCountryResponse_element {

        public String GetCitiesByCountryResult;

        private String[] GetCitiesByCountryResult_type_info = new String[]{'GetCitiesByCountryResult','http://www.webserviceX.NET',null,'0','1','false'};

        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};

        private String[] field_order_type_info = new String[]{'GetCitiesByCountryResult'};

    }

    public class GlobalWeatherSoap {

        public String endpoint_x = 'http://www.webservicex.com/globalweather.asmx';

        public Map<String,String> inputHttpHeaders_x;

        public Map<String,String> outputHttpHeaders_x;

        public String clientCertName_x;

        public String clientCert_x;

        public String clientCertPasswd_x;

        public Integer timeout_x;

        private String[] ns_map_type_info = new String[]{'http://www.webserviceX.NET', 'GlobalWhetherClass'};

        public String GetCitiesByCountry(String CountryName) {

            GlobalWhetherClass.GetCitiesByCountry_element request_x = new GlobalWhetherClass.GetCitiesByCountry_element();

            request_x.CountryName = CountryName;

            GlobalWhetherClass.GetCitiesByCountryResponse_element response_x;

            Map<String, GlobalWhetherClass.GetCitiesByCountryResponse_element> response_map_x = new Map<String, GlobalWhetherClass.GetCitiesByCountryResponse_element>();

            response_map_x.put('response_x', response_x);

            WebServiceCallout.invoke(

              this,

              request_x,

              response_map_x,

              new String[]{endpoint_x,

              'http://www.webserviceX.NET/GetCitiesByCountry',

              'http://www.webserviceX.NET',

              'GetCitiesByCountry',

              'http://www.webserviceX.NET',

              'GetCitiesByCountryResponse',

              'GlobalWhetherClass.GetCitiesByCountryResponse_element'}

            );

            response_x = response_map_x.get('response_x');

            return response_x.GetCitiesByCountryResult;

        }

        public String GetWeather(String CityName,String CountryName) {

            GlobalWhetherClass.GetWeather_element request_x = new GlobalWhetherClass.GetWeather_element();

            request_x.CityName = CityName;

            request_x.CountryName = CountryName;

            GlobalWhetherClass.GetWeatherResponse_element response_x;

            Map<String, GlobalWhetherClass.GetWeatherResponse_element> response_map_x = new Map<String, GlobalWhetherClass.GetWeatherResponse_element>();

            response_map_x.put('response_x', response_x);

            WebServiceCallout.invoke(

              this,

              request_x,

              response_map_x,

              new String[]{endpoint_x,

              'http://www.webserviceX.NET/GetWeather',

              'http://www.webserviceX.NET',

              'GetWeather',

              'http://www.webserviceX.NET',

              'GetWeatherResponse',

              'GlobalWhetherClass.GetWeatherResponse_element'}

            );

            response_x = response_map_x.get('response_x');

            return response_x.GetWeatherResult;

        }

    }

}

but new requirement is whenever select the country then display the state values in visualforce page .

Thanks in advance

Raj
1 answer
  1. Jun 6, 7:34 AM

    Hi, 

     

    You'll need a Visualforce page with an Apex controller that calls your GlobalWhetherClass — using a <apex:actionSupport> to re-render the cities list when country changes.  

     

    public class WeatherController {

    public String selectedCountry { get; set; }

    public String citiesResult { get; set; }

    public List<SelectOption> getCountries() {

    return new List<SelectOption>{

    new SelectOption('India', 'India'),

    new SelectOption('United States', 'United States'),

    new SelectOption('United Kingdom', 'United Kingdom')

    // Add more as needed

    };

    }

    public void fetchCities() {

    if (String.isNotBlank(selectedCountry)) {

    GlobalWhetherClass.GlobalWeatherSoap svc = new GlobalWhetherClass.GlobalWeatherSoap();

    citiesResult = svc.GetCitiesByCountry(selectedCountry);

    }

    }

    }

     

    <apex:page controller="WeatherController">

    <apex:form>

    <apex:pageBlock title="Weather Lookup">

    <apex:pageBlockSection>

    <apex:selectList value="{!selectedCountry}" size="1">

    <apex:selectOptions value="{!countries}"/>

    <apex:actionSupport event="onchange"

    action="{!fetchCities}"

    reRender="citiesBlock"/>

    </apex:selectList>

    </apex:pageBlockSection>

    <apex:pageBlockSection id="citiesBlock">

    <apex:outputText value="{!citiesResult}" escape="false"/>

    </apex:pageBlockSection>

    </apex:pageBlock>

    </apex:form>

    </apex:page>

     

     

    • User selects a country from the dropdown
    • onchange fires fetchCities() via actionSupport
    • Controller calls GetCitiesByCountry on your SOAP class
    • Result re-renders in citiesBlock without a full page refresh

     

    Make sure

    http://www.webservicex.com is added to your Remote Site Settings

    (Setup → Remote Site Settings) — otherwise the callout will be blocked. 

      

    Hope this helps!

0/9000