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
nishanth0208nishanth0208 

How to retrieve field value while i am getting field value id when i am trying to retrieve?

Hi All,

          I am trying to retrieve a picklist value from page to control. In the control, I am getting the field value id and not the field value text. And i am retrieving using property fields like public String selecteduser{set;get;}.I need to use that retrieved value in a where clause of an query. Please tell me how can i get the picklist text value?

 

 Tons of Thanks,

  Nishanth.

 

KeithJKeithJ

Hi ,

 

can you post your code please?

Regards

Ispita_NavatarIspita_Navatar

I think you have to tweek the way you are generating your picklist to get the desired result. In the code for generation of picklist , in portion where you are assigning text and value of a picklist option programatically modify the value portion such that is look like this:-

 say   id+"-"+ text then as you get the value on the controller you can split it at the point where "-" is and extract the text.

In order to help you in a better way please do share the code which is bothering you so that we can give you a precise solution.

 

nishanth0208nishanth0208

public class LocationControl{
      public LocationMaster__c lm{get;set;}

         List<LocationMaster__c> routelist = new List<LocationMaster__c>();
         List<LocationMaster__c> doclist = new List<LocationMaster__c>();
         List<LocationMaster__c> druggistlist = new List<LocationMaster__c>();
         List<LocationMaster__c> stockistlist = new List<LocationMaster__c>();
         List<selectOption> usersOptions=new  List<selectOption>();
         List<selectOption> usersOptions1=new  List<selectOption>();
         List<selectOption> usersOptions2=new  List<selectOption>();
         List<selectOption> usersOptions3=new  List<selectOption>();
           
           public String selecteduser{get;set;}
           public String selecteduser1{get;set;}
           public String selecteduser2{get;set;}
           public String selecteduser3{get;set;}
          String selecdteduser='Hyderabad-Afzalgunz-hyderabad';
   
           public LocationControl(ApexPages.StandardController ctrl){
              LocationMaster__c lm= new LocationMaster__c();
              LocationMaster__c lm1= new LocationMaster__c();
  
              lm1.route__c=lm.route__c;
              routelist=[select route__c from LocationMaster__c];
              usersOptions.add(new selectOption('Select','Select'));
              for(LocationMaster__c userloop:routelist){            
                usersOptions.add( new selectOption(userloop.id,userloop.route__c));
                
          }
       }   
   public PageReference doprocess(){

    System.debug('___________________________'+selecteduser);// this is where i am getting id instead of picklist value
     usersoptions1.clear();
       doclist=[select DoctorName__r.Name from LocationMaster__c where route__c=:selecteduser];
       usersOptions1.add(new selectOption('Select','Select'));
        for(LocationMaster__c userloop:doclist){            
            usersOptions1.add( new selectOption(userloop.id,userloop.DoctorName__r.Name));
         } 
        druggistlist=[select DruggistName__r.Name from LocationMaster__c ];
          usersoptions2.clear();
        usersOptions2.add(new selectOption('Select','Select'));
        for(LocationMaster__c userloop:druggistlist){            
            usersOptions2.add( new selectOption(userloop.id,userloop.DruggistName__r.Name));
         } 

        stockistlist=[select StockistName__r.Name from LocationMaster__c ];
        usersoptions3.clear();
        usersOptions3.add(new selectOption('Select','Select'));
        for(LocationMaster__c userloop:stockistlist){            
            usersOptions3.add( new selectOption(userloop.id,userloop.StockistName__r.Name));
         }  
          return null;
         }

  public List<selectoption> getuserslist(){

        return usersOptions;
      } 
    public List<selectoption> getuserslist1(){
        return usersOptions1;
      } 
      public List<selectoption> getuserslist2(){
        return usersOptions2;
      } 
        public List<selectoption> getuserslist3(){
        return usersOptions3;
      } 
   }

nishanth0208nishanth0208
<apex:page standardcontroller="LocationMaster__c" extensions="LocationControl">
   <apex:actionStatus id="LoadingStatus"  startText="Loading........"  />
   <apex:pageMessages />
   <apex:form id="formid">
   <script>
       function func(){
 var a=document.getElementById("{!$Component.formid.pageblockid.pageblocksectionid.RouteList}").value;
         }
   </script>
   <apex:pageblock id="pageblockid">
   <apex:pageblockButtons >
       <apex:commandButton value="Go" onclick="func()"/>
   </apex:pageblockButtons>
    <apex:pageblocksection columns="1" id="pageblocksectionid">
        <apex:outputLabel value="Route:" for="RouteList"/> 
        <apex:selectList id="RouteList" value="{!LocationMaster__c.Route__c}" size="1" onchange="MyActionfunc()"> 
         <apex:actionFunction action="{!doprocess}" name="MyActionfunc" status="LoadingStatus" rerender="doctorlistblock" rendered="true"/>
         <apex:selectOptions value="{!userslist}"/> 
      </apex:selectList> <br/>
       </apex:pageblocksection>
      </apex:pageblock>
   
    <apex:pageblock id="doctorlistblock" >

    <apex:pageblocksection columns="1">
        <apex:outputLabel value="Doctor" for="DoctorList"/> 
        <apex:selectList id="DoctorList" value="{!selecteduser1}" size="1"> 
         <apex:actionFunction action="{!doprocess}" name="MyActionfunc" status="LoadingStatus" rerender="doctorlistblock" rendered="true"/> 
         <apex:selectOptions value="{!userslist1}"/> 
        </apex:selectList> <br/>
    
        <apex:outputLabel value="Druggist" for="DruggistList"/> 
        <apex:selectList id="DruggistList" value="{!selecteduser2}" size="1" onchange="MyActionfunc()"> 
         <apex:actionFunction action="{!doprocess}" name="MyActionfunc" status="LoadingStatus" /> 
         <apex:selectOptions value="{!userslist2}"/> 
        </apex:selectList> <br/>
    
      </apex:pageblock>
   </apex:form>
 </apex:page>