+ Start a Discussion
veeru_pariveeru_pari 

Displaying picklist values with ques and answers in VF page

Hi,
I have other query where i have a custom object in that i have fields questions(data type text area),answers(answer also same ) an pick list having internal user,external user and All users. now my requirement is i want to display the pick list values in vf page and if the user selects internal option in picklist then page shpuld display question and answer related to internal and if he selects all it should display all the ques and answers.

Will you u please tell me how to achieve this req

Thanks in advance

Veeraiah
DevADSDevADS
Hey Veeraiah,

You can do it using SelectList. Whenever the User will click on Search Buttion, You will Query on object Where the the use will be of type the selected picklist field. Here you will get List<Custom_Object> records which will have questions & answers of the slected picklist type. Just show this list on VF page.


1) public List<String> selectedValue {get;set;}
public List<SelectOption> getUserType()
{
  List<SelectOption> options = new List<SelectOption>();
     
   Schema.DescribeFieldResult fieldResult =CustomObject__c.getUserType__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
     
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }    
   return options;
}

With our controller logic all complete, we can call the getUserType() method from our Visualforce page,  and populate the <apex:selectList> tag:

2) <apex:selectList id="countries" value="{selectedValue}"
         size="1" required="true">
  <apex:selectOptions value="{!countries}"/>
</apex:selectList>

3) You will query in that Custom object when the Search button will be click with selectedValue which will return of list of records. Now rerender the form or Outputpanel.

Let me know if you didn't understand the scenario or any query. Happy Coding!!!
veeru_pariveeru_pari
could u please help me in detail
veeru_pariveeru_pari
Hi Amit, Could u please explain me how the below statement work You will query in that Custom object when the Search button will be click with selectedValue which will return of list of records. Now rerender the form or Outputpanel. Thanks On Thu, Jan 9, 2014 at 3:23 PM, veeru chowdary wrote:
veeru_pariveeru_pari
Need code snippet On Thu, Jan 9, 2014 at 3:38 PM, veeru chowdary wrote:
DevADSDevADS
Hey Veeru,

I am just giving you the templateChange your code with template

Controller :
public class VEERU_PageController{

    public String selectedValue {get;set;}
    public List<SelectOption> getUserType()
    {
        List<SelectOption> options = new List<SelectOption>();
        Schema.DescribeFieldResult fieldResult = Book__c.UserType__c.getDescribe(); 
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); // Here you will get the picklist values
        options.add(new SelectOption('All','All'));
        for( Schema.PicklistEntry f : ple)
        {
            options.add(new SelectOption(f.getLabel(), f.getValue()));
        }    
        return options;

    }
   
    public List<Book__c> search(){
        System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
        List<Book__c> temp = new List<Book__c>();
        String queryString;
        if(selectedValue == 'ALL') queryString ='SELECT id,Question__c,Answer__c from CustomObject__c';
        else if(selectedValue == 'Internal') queryString ='SELECT id,Question__c,Answer__c from CustomObject__c WHERE UserType__c = 'Internal'';
        else if(selectedValue == 'External') queryString ='SELECT id,Question__c,Answer__c from CustomObject__c WHERE UserType__c = 'External'';
        temp = Database.query(queryString);
        return temp;
    }

}

Page 
<apex:page controller="VEERU_PageController">
  <apex:form id="form1">
    <apex:selectList id="countries" value="{!selectedValue}"
    size="1" required="true">
        <apex:selectOptions value="{!UserType}"/>
    </apex:selectList>
    <apex:commandButton value="Search" action="{!search}" rerender="form1"/>
    <!--  Take table here & display your record  
      -->

    </apex:form>
</apex:page>

Hope this will help, If you still facing any issues, let me know! Happy Coding!!
DevADSDevADS
Hey,

It  seems all correct to me, I am also not facing the compatibility error. May be you know this that the error is occuring due to the LHS & RHS of Assignment operator is different. Check your code or Share your code. Reply in your open ticket!
Happy Coding!!
veeru_pariveeru_pari
Hi Amith, Here is the code public class FAQCu { public List selectedValue {get;set;} public List getUserType() { List options = new List(); Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe(); List ple = fieldResult.getPicklistValues(); options.add(new SelectOption('AllUsers','AllUsers')); for( Schema.PicklistEntry f : ple) { options.add(new SelectOption(f.getLabel(), f.getValue())); } return options; } public List getSearch(){ //System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here List temp = new List(); String queryString; 22/ *if(selectedValue=='AllUsers') * queryString='SELECT Question__c,Answer__c from FAQ__c WHERE Users__c ="AllUsers"'; else if(selectedValue=='InternalUsers') queryString='SELECT id,Question__c,Answer__c from FAQ__c WHERE Users__c ="InternalUsers"'; else if(selectedValue=='ExternalUsers') queryString='SELECT id,Question__c,Answer__c from FAQ__c WHERE Users__c ="ExternalUsers"'; temp = Database.query(queryString); return temp; } } Vf is: In the above line 22 is marked Thanks
DevADSDevADS
Try this code once

public class FAQCu {

    public List selectedValue {get; set;}
   
    public List getUserType() {
        List options = new List();
        Schema.DescribeFieldResult fieldResult = FAQ__c.Users__c.getDescribe();
        List ple = fieldResult.getPicklistValues();
        options.add(new SelectOption('AllUsers', 'AllUsers'));
        for (Schema.PicklistEntry f: ple) {
            options.add(new SelectOption(f.getLabel(), f.getValue()));
        }
        return options;
    }
    public List<FAQCu__c> getSearch()
    {
     //System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
        List<FAQCu__c> temp = new List<FAQCu__c>(); //make list of your custom object
        String queryString;
        if(selectedValue=='AllUsers')  queryString='SELECT Question__c,Answer__c from FAQ__c WHERE Users__c ='AllUsers'';
        else if(selectedValue=='InternalUsers') queryString='SELECT id,Question__c,Answer__c from FAQ__c WHERE Users__c ='InternalUsers'';
        else if(selectedValue=='ExternalUsers') queryString='SELECT id,Question__c,Answer__c from FAQ__c WHERE Users__c ='ExternalUsers'';
        temp = Database.query(queryString);
        return temp;
    }
}
veeru_pariveeru_pari
Hi Amith, Yeaa my code was the same when i am trying to run this code i am getting the error:(expecting a semi-colon, found 'queryString' at line 22 column 3) public class FAQCu { public List selectedValue {get;set;} public List getUserType() { List options = new List(); Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe(); List ple = fieldResult.getPicklistValues(); // options.add(new SelectOption('All','All')); for( Schema.PicklistEntry f : ple) { options.add(new SelectOption(f.getLabel(), f.getValue())); } return options; } public List getSearch(){ System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here List temp = new List();/*/This is my actual custom obj* String queryString; f(selectedValue=='AllUsers') *Line 22// queryString='SELECT Question__c,Answer__c from FAQ__c WHERE Users__c ='AllUsers'';* else if(selectedValue=='InternalUsers') queryString='SELECT id,Question__c,Answer__c from FAQ__c WHERE Users__c ='InternalUsers''; else if(selectedValue=='ExternalUsers') queryString='SELECT id,Question__c,Answer__c from FAQ__c WHERE Users__c ='ExternalUsers''; temp = Database.query(queryString); return temp; } }
veeru_pariveeru_pari
LinkedIn
veeru_pariveeru_pari
Hi , I'd like to add you to my professional network on LinkedIn. - veeraiah Accept: https://www.linkedin.com/e/v2?e=-esvkof-hxn5axeg-3f&a=preRegInvite&tracking=eml-guest-invite-cta&ek=invite_guest&invitationID=5894776477689327616&sharedKey=0pvpNUI7 You are receiving Invitation emails. Unsubscribe here: https://www.linkedin.com/e/v2?e=-esvkof-hxn5axeg-3f&t=uns&tracking=eml-guest-invite-unsubscribe&ek=invite_guest&id=20061∣=-1&aid=iuehc9r3r0sm6r3&eid=-esvkof-hxn5axeg-3f&email=1cukf1jx2dypf52w%2Ehotd1jtolg5g8fqs%40p02is97l7lmog0m6%2Eovrzf%2Ef-55kkmai%2Ena10%2Echatter%2Esalesforce%2Ecom Learn why we included this at the following link: http://www.linkedin.com/e/v2?e=-esvkof-hxn5axeg-3f&a=customerServiceUrl&ek=invite_guest&articleId=4788 © 2014, LinkedIn Corporation. 2029 Stierlin Ct. Mountain View, CA 94043, USA
veeru_pariveeru_pari
Hi , I'd like to add you to my professional network on LinkedIn. - veeraiah Accept: https://www.linkedin.com/e/v2?e=-km61ql-hxn5ax7y-w&a=preRegInvite&tracking=eml-guest-invite-cta&ek=invite_guest&invitationID=5894776475034341376&sharedKey=1id33yfD You are receiving Invitation emails. Unsubscribe here: https://www.linkedin.com/e/v2?e=-km61ql-hxn5ax7y-w&t=uns&tracking=eml-guest-invite-unsubscribe&ek=invite_guest&id=20061∣=-1&aid=iuehc9r3r0sm6r3&eid=-km61ql-hxn5ax7y-w&email=0-22th0gnr2g61um%2Eybktxkesnfu8saai%40vgq5nxjpowbb94jr%2E4a3fl0n%2Ef-55kkmai%2Ena10%2Echatter%2Esalesforce%2Ecom Learn why we included this at the following link: http://www.linkedin.com/e/v2?e=-km61ql-hxn5ax7y-w&a=customerServiceUrl&ek=invite_guest&articleId=4788 © 2014, LinkedIn Corporation. 2029 Stierlin Ct. Mountain View, CA 94043, USA