+ Start a Discussion
veeru_pariveeru_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
Best Answer chosen by veeru_pari
GlynAGlynA
Change line 2:

public List<String> selectedValue {get;set;}

to:

public String selectedValue {get;set;}

and it should work.

-Glyn

All Answers

GlynAGlynA
Change line 2:

public List<String> selectedValue {get;set;}

to:

public String selectedValue {get;set;}

and it should work.

-Glyn
This was selected as the best answer
veeru_pariveeru_pari
Even after changing that its giving me the same error
veeru_pariveeru_pari
Thanks Amith the problem solved need to display the result on VF
veeru_pariveeru_pari
Thanks Ajith it soled i need to display it on vf i am trying that
veeru_pariveeru_pari
Thanks Glyn On Fri, Jan 10, 2014 at 2:30 PM, veeru chowdary
veeru_pariveeru_pari
Hi Glyn, I want to display the result of getSearch() in vf page how can i do that Thanks On Fri, Jan 10, 2014 at 2:32 PM, veeru chowdary
veeru_pariveeru_pari
Hi, Glyn how can i display the output of the below code so that if i select internal the page should populate with question and answer. *public String 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();* * 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;* * }* Thanks On Fri, Jan 10, 2014 at 2:46 PM, veeru chowdary
GlynAGlynA
Veeru,

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

GlynAGlynA
<pre>
    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>
veeru_pariveeru_pari
Hi Glyn, My actual requirement was like 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 should display question and answer related to internal and if he selects ExternalUser it should display Questio and answer of External user and if he selects all user it should display All the Q&A .So how could i achieve this.For that i wrote the above code .i am getting the pick list but not the Q&A related to that.Please help me on this. Thanks Veeraiah
GlynAGlynA
Veeraiah,

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

GlynAGlynA
<pre>
<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>
GlynAGlynA
Whoops!  I didn't close the actionSupport.  It should be:

<pre>
<apex:actionSupport event="onchange" rerender="questions" />
</pre>

-Glyn
veeru_pariveeru_pari
Hi GlynA, I have tried with vf code which u have provide for the controller but i am getting the error ( Visualforce Error Help for this Page System.NullPointerException: Argument 1 cannot be null Class.FAQCu.getSearch: line 26, column 1 ) In the above code the line 26 is marked below it is in getSearch method below is the code where i have hilighted line 26 in the code public class FAQCu { public String 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(); 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'; 26line// * temp = Database.query(queryString);* return temp; } } Thanks in advance Veeraiah
GlynAGlynA
You will get this NullPointerException if the selectedValue is none of the three values you are checking for.  This is because queryString will remain uninitialized.  My version of the code avoids this by checking to see if the selectedValue is in set_AcceptedValues.  If not, it doesn't do the query.

Are there values of the Users__c field other than those three?

-Glyn
GlynAGlynA
I think your getSearch method should just be:

<pre>
    public List<FAQ__c> getSearch()
    {
        return [SELECT Users__c, Question__c, Answer__c FROM FAQ__c WHERE Users__c = :selectedValue]
    }
</pre>

-Glyn
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=-w20msb-hxn5ax5c-h&a=preRegInvite&tracking=eml-guest-invite-cta&ek=invite_guest&invitationID=5894776467924987905&sharedKey=MG5lMrQL You are receiving Invitation emails. Unsubscribe here: https://www.linkedin.com/e/v2?e=-w20msb-hxn5ax5c-h&t=uns&tracking=eml-guest-invite-unsubscribe&ek=invite_guest&id=20061∣=-1&aid=iuehc9r3r0sm6r3&eid=-w20msb-hxn5ax5c-h&email=0-343ti5rv0lzriy%2Ej5p5gmaa02hsazdd%40pnc3dxt151kuqyoi%2Ek528pus%2Ef-55kkmai%2Ena10%2Echatter%2Esalesforce%2Ecom Learn why we included this at the following link: http://www.linkedin.com/e/v2?e=-w20msb-hxn5ax5c-h&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=g72lvq-hxn5axcu-20&a=preRegInvite&tracking=eml-guest-invite-cta&ek=invite_guest&invitationID=5894776477836140544&sharedKey=d0oKLKmy You are receiving Invitation emails. Unsubscribe here: https://www.linkedin.com/e/v2?e=g72lvq-hxn5axcu-20&t=uns&tracking=eml-guest-invite-unsubscribe&ek=invite_guest&id=20061∣=-1&aid=iuehc9r3r0sm6r3&eid=g72lvq-hxn5axcu-20&email=0-17165r7tmb07jx%2E23kke6yrmrwu6fmv%40zmhdf48xcji45ccj%2E34nskgv%2Ef-55kkmai%2Ena10%2Echatter%2Esalesforce%2Ecom Learn why we included this at the following link: http://www.linkedin.com/e/v2?e=g72lvq-hxn5axcu-20&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=-9jshup-hxn5ax5g-2&a=preRegInvite&tracking=eml-guest-invite-cta&ek=invite_guest&invitationID=5894776471699873792&sharedKey=dQTpdYTS You are receiving Invitation emails. Unsubscribe here: https://www.linkedin.com/e/v2?e=-9jshup-hxn5ax5g-2&t=uns&tracking=eml-guest-invite-unsubscribe&ek=invite_guest&id=20061∣=-1&aid=iuehc9r3r0sm6r3&eid=-9jshup-hxn5ax5g-2&email=0-2px1c6p1bejrix%2E34n5pbd46tgiyzkc%40dmvn0rzyypacyd74%2Ewd1yhw8%2Ef-55kkmai%2Ena10%2Echatter%2Esalesforce%2Ecom Learn why we included this at the following link: http://www.linkedin.com/e/v2?e=-9jshup-hxn5ax5g-2&a=customerServiceUrl&ek=invite_guest&articleId=4788 © 2014, LinkedIn Corporation. 2029 Stierlin Ct. Mountain View, CA 94043, USA