You need to sign in to do that
Don't have an account?

Display output
Hi,
I want to display the output of the getsearch method in the below code in vf page so that if i select one pick list i should get the answer
public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
List<Schema.PicklistEntry> 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<FAQ__c> getSearch(){
System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
List<FAQ__c> temp = new List<FAQ__c>();
String queryString;
if(selectedValue=='AllUsers')
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c =AllUsers';
else if(selectedValue=='InternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =InternalUsers';
else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =ExternalUsers';
temp = Database.query(queryString);
return temp;
}
I want to display the output of the getsearch method in the below code in vf page so that if i select one pick list i should get the answer
public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =FAQ__c.Users__c.getDescribe();
List<Schema.PicklistEntry> 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<FAQ__c> getSearch(){
System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
List<FAQ__c> temp = new List<FAQ__c>();
String queryString;
if(selectedValue=='AllUsers')
queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c =AllUsers';
else if(selectedValue=='InternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =InternalUsers';
else if(selectedValue=='ExternalUsers')
queryString='SELECT Users__c,Question__c,Answer__c from FAQ__c WHERE Users__c =ExternalUsers';
temp = Database.query(queryString);
return temp;
}
Your querystring is wrong, so that It will return null records, Put escape characters.
Correct your querystring to queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \' AllUsers\' ';
Hope this will help. Happy Coding!!
http://www.mindfiresolutions.com/Salesforce-Custom-Picklist-in-VisualForce-Page-1480.php
Thanks in advance* On Fri, Jan 10, 2014 at 4:00 PM, veeru chowdary
options.add(new SelectOption('All','All'));
if(selectedValue=='AllUsers') queryString='SELECT Users__c,Question__c,Answer__cfrom FAQ__c WHERE Users__c = \'AllUsers\' ';
Please initialise the default value to selectedValue in the contructor: public String selectedValue {get;set;}