You need to sign in to do that
Don't have an account?
veeru_pari
Compatible error
Hi ,
In the below code if i try to run i am getting. the error like this (FAQCu Compile Error: Comparison arguments must be compatible types: LIST<String>, String at line 20 column 12)I have hilighted the errior in bold letters in the below code
public class FAQCu {
public List<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;
Line 20// 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;
}
}
and the vf page is:
<apex:page controller="FAQCu">
<apex:form >
<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
<apex:selectOptions value="{!userType}"/>
</apex:selectList>
</apex:form>
</apex:page>
Please help me on this
Thanks
Veeraiah
In the below code if i try to run i am getting. the error like this (FAQCu Compile Error: Comparison arguments must be compatible types: LIST<String>, String at line 20 column 12)I have hilighted the errior in bold letters in the below code
public class FAQCu {
public List<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;
Line 20// 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;
}
}
and the vf page is:
<apex:page controller="FAQCu">
<apex:form >
<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
<apex:selectOptions value="{!userType}"/>
</apex:selectList>
</apex:form>
</apex:page>
Please help me on this
Thanks
Veeraiah
public List<String> selectedValue {get;set;}
to:
public String selectedValue {get;set;}
and it should work.
-Glyn
All Answers
public List<String> selectedValue {get;set;}
to:
public String selectedValue {get;set;}
and it should work.
-Glyn
The code in the next post will at least compile. I've done some optimization as well. Let me know if you have questions.
-Glyn
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();
for ( Schema.PicklistEntry f : ple )
{
options.add( new SelectOption( f.getLabel(), f.getValue() ) );
}
return options;
}
public List<FAQ__c> getSearch()
{
Set<String> set_AcceptedValues = new Set<String>
{ 'AllUsers',
'InternalUsers',
'ExternalUsers'
};
if ( !set_AcceptedValues.contains( selectedValue ) ) return null;
return (List<FAQ__c>) Database.query
( 'SELECT Users__c, Question__c, Answer__c '
+ 'FROM FAQ__c '
+ 'WHERE Users__c = \'' + selectedValue + '\''
);
}
</pre>
I've posted a version of your VF code below that should display the questions and answers in a data table. I've added actionSupport to your selectList so that the table will get rerendered anytime the selection changes.
-Glyn
<apex:page controller="FAQCu">
<apex:form >
<apex:selectList id="users" value="{!selectedValue}" size="1" required="true">
<apex:selectOptions value="{!userType}"/>
<apex:actionSupport event="onchange" rerender="questions"
</apex:selectList>
<apex:dataTable value="{!search}" var="faq" id="questions">
<apex:column>
<apex:outputText value="{!faq.Question__c}"/>
</apex:column>
<apex:column>
<apex:outputText value="{!faq.Answer__c}"/>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:page>
</pre>
<pre>
<apex:actionSupport event="onchange" rerender="questions" />
</pre>
-Glyn
Are there values of the Users__c field other than those three?
-Glyn
<pre>
public List<FAQ__c> getSearch()
{
return [SELECT Users__c, Question__c, Answer__c FROM FAQ__c WHERE Users__c = :selectedValue]
}
</pre>
-Glyn