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
Sivasankari MuthuSivasankari Muthu 

Doubt : how to pass the standard state and country picklist to apex controller page ​

My scenario is,
I have to get the details by location(State or Country).1st preference is State.
My output will be,
User-added image
The input fields are Standard Country and State picklist .
The state or country (input) has  pass to the apex controller.
[ Eg: :USA State: NY---- input will be NY(State)
 2. country:Iceland  State : No States ,------ input will be  Iceland(Country) 
I dont know how to pass theat selected state picklist value to apex controller.

But i written some piece of codes.Please verify it and correct it. If anyone knows please tell me.

My Apex Code:

Public with sharing class SOSLController{
 Public List<loc__c> location {get;set;} // location
    public String imageURL{get;set;} // display a image
 Public String searchStr{get;set;} // find a string
 private ApexPages.StandardController stdController;
  /* display a image -method*/
 public  SOSLController(ApexPages.StandardController stdController)
    List< document > documentList=[select name from document where 
    /* find a string and  run the sosl query*/
  Public void soslDemo_method(){
   location = New List<loc__c>();
   if(searchStr.length() > 1){
   String searchStr1 = searchStr;
     //  System.debug('message');
       String searchQuery = 'FIND \'' + searchStr1 + '\' IN ALL FIELDS RETURNING  loc__c(Comp__c, Type__c,Client__c, Competitor__c,Event_Name__c, evt_Des__c , Et_Addr__c, Dt_Ti__c, Ct_person__c,Ph_Num__c )';
   List<List <sObject>> searchList = search.query(searchQuery);
   location = ((List<loc__c>)searchList[0]);
       /* Message */
   if(location.size() == 0){
       apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Sorry, Type the location correctly or There is no details of the requested location found'));
   apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please enter the location..'));


<apex:page standardController="Contact"  extensions="SOSLController"  sidebar="false" showHeader="false">
  <apex:form >
       <apex:image url="{!imageURL}">
      <apex:pageBlock title="Enter a location" id="acct1">
          <apex:outputLabel value="Country" />
          <apex:inputField value="{!contact.MailingCountryCode}" />
            <apex:outputLabel value="State" />
          <apex:inputField value="{!contact.MailingStateCode}" />
    <apex:commandButton value="Submit" action="{!soslDemo_method}"  reRender="acct,error,acct1" />
    <apex:outputPanel title="" id="error">
     <apex:pageMessages ></apex:pageMessages>
    <apex:pageBlock title="Details of technical events" id="acct">
    <apex:pageblockTable value="{!location }" var="acc">
           <apex:column value="{!acc.Comp__c}"/>
         <apex:column value="{!acc.Type__c}"/>
          <apex:column value="{!acc.Client__c}"/>
        <apex:column value="{!acc.Competitor__c}"/>
        <apex:column value="{!acc.Event_Name__c}"/>
          <apex:column value="{!acc.evt_Des__c}"/>
        <apex:column value="{!acc.Et_Addr__c}"/>
          <apex:column value="{!acc.Dt_Ti__c}"/>
        <apex:column value="{!acc.Ct_Person__c}"/>
          <apex:column value="{!acc.Ph_Num__c}"/>

Thanks and Regards,
Sandy GaliSandy Gali
Use the get record method of standard controller, inside the constructor to get the values from Apex page

Code would be something like this.

VF page
<apex:page standardController="Contact" extensions="SOSLController">
<apex:form >
    <apex:pageBlock mode="edit">
        <apex:pageBlockSection >
            <apex:inputField value="{!Contact.MailingCountryCode}" />
            <apex:inputField value="{!Contact.MailingStateCode}" />
        <apex:commandButton value="Submit" action="{!soslDemo_method}"/>

public with sharing class SOSLController {
private final Contact cnct;

    public SOSLController(ApexPages.StandardController controller) {
    this.cnct = (Contact)controller.getRecord();
    system.debug('Inside the constructor');
    Public void soslDemo_method(){
    system.debug('inside sosl method');
    system.debug('country is'+cnct.MailingCountryCode);
    system.debug('state is'+cnct.MailingStateCode);