1

i am having multiple checkbox according to selected checkbox query have to perform search operation.

public class actionSupportController {
    public List<PCS_Household__c> lstQuery{get;set;} 
    public List<PCS_Household__c> OnlstQuery{get;set;}
    public List<Characteristics__c> selctchr{get;set;}
    public Characteristics__c sct{get;set;}
    public string ID_c{get;set;}      
    public string test{get;set;}
    public string Good_with_Cats_c{get;set;}    
    public string Active_c{get;set;}
    public string HighNeed_c{get;set;}    
    public string kid_friendly_c{get;set;}
    public string Non_shedder_c{get;set;}    
    public string Predatory_Tendencies_c{get;set;}

    public List<Pets_Information__c> selctpet{get;set;}

    Public Boolean Good{get;set;}

    public void dochar(){
        string query='';
        system.debug('==Good_with_Cats_c=='+Good_with_Cats_c);    
       query='SELECT Name,ID,Good_with_Cats__c,Pet_ID__r.Gender__c,Pet_ID__r.Height__c,Pet_ID__r.Name__c,Pet_ID__r.pet__c,Pet_ID__r.Pet_Photo__c,Pet_ID__r.Status__c FROM Characteristics__c where Good_with_Cats__c=\''+Good_with_Cats_c+'\' or Active__c=\''+Active_c+'\' or HighNeed__c=\''+HighNeed_c+'\' or kid_friendly__c=\''+kid_friendly_c+'\' or Non_shedder__c=\''+Non_shedder_c+'\' or Predatory_Tendencies__c=\''+Predatory_Tendencies_c+'\'';
       //query='SELECT Name,ID,Good_with_Cats__c,Pet_ID__r.Gender__c,Pet_ID__r.Height__c,Pet_ID__r.Name__c,Pet_ID__r.pet__c,Pet_ID__r.Pet_Photo__c,Pet_ID__r.Status__c FROM Characteristics__c where Good_with_Cats__c\''+Good_with_Cats_c+'\' or Active__c=\''+Active_c+'\'';
        system.debug('==query=='+query);
        selctchr=Database.query(query);    
        system.debug('==selctchr=='+selctchr);
    }


    public PageReference incrementCounter() {
       string Query='';
        Query='SELECT ID,Name,Household__c,Phone__c,of_Childrens__c,of_Exiting_Pets__c,Address__c,Previous_Dog__c FROM PCS_Household__c where ID=:test';        
        system.debug('==Query=='+Query);
        OnlstQuery=Database.query(Query);
        system.debug('==OnlstQuery=='+OnlstQuery);
        return null;
    }

     public Void doSearch(){
        string Query='';
        Query='SELECT ID,Name,Household__c,Phone__c,of_Childrens__c,of_Exiting_Pets__c,Address__c,Previous_Dog__c FROM PCS_Household__c where Household__c LIKE \'%'+ID_c+'%\'';
         system.debug('==ID_c=='+ID_c);
        system.debug('==Query=='+Query);
        lstQuery=Database.query(Query);
        system.debug('==lstQuery=='+lstQuery);
    }

    public void nullify(){
        lstQuery.clear();
    }

    public PageReference nextpage() {

        upsert OnlstQuery;

        return Page.cc;
    }

}

Visualforce:

<apex:page Controller="actionSupportController">
   <apex:form >
       <apex:pageBlock >
            Household Name: <apex:inputText value="{!ID_c}"/>          
           </apex:pageBlock>
    <apex:pageBlock title="Characteristics Information">

        <apex:inputCheckbox value="{!Active_c}" />Active<br/>
        <apex:inputCheckbox value="{!Good_with_Cats_c}" />Good with Cats<br/>
        <apex:inputCheckbox value="{!HighNeed_c}" />HighNeed<br/>
        <apex:inputCheckbox value="{!kid_friendly_c}" />Kid Friendly<br/>
        <apex:inputCheckbox value="{!Non_shedder_c}" />Non Shedder<br/>
        <apex:inputCheckbox value="{!Predatory_Tendencies_c}" />Prediator Tendency<br/>

       <br/><apex:commandButton value="Search" action="{!dochar}" rerender="sblck"/>
    </apex:pageBlock>
    <apex:outputPanel id="sblck">
    <apex:pageBlock title="Search Results">
    <apex:pageBlockTable width="80%" value="{!selctchr}" var="eachpe">
        <apex:column width="80%" value="{!eachpe.Name}"/>
        <apex:column width="80%" value="{!eachpe.Pet_ID__r.Name__c}"/>
        <apex:column width="80%" value="{!eachpe.Pet_ID__r.Gender__c}"/>
        <apex:column width="80%" value="{!eachpe.Pet_ID__r.Height__c}"/>       
        <apex:column width="80%" value="{!eachpe.Pet_ID__r.pet__c}"/>
        <apex:column width="80%" value="{!eachpe.Pet_ID__r.Pet_Photo__c}"/>
        <apex:column width="80%" value="{!eachpe.Pet_ID__r.Status__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:outputPanel>
       <apex:commandButton value="Request Adoption"/>
   </apex:form>
</apex:page>
2
  • 2
    what do you mean by multiple checkbox error? Please put some additional details with this question. screenshot, SFDC error message
    – Himanshu
    May 25, 2016 at 18:08
  • i have updated my code.. please have a look
    – user31850
    May 25, 2016 at 18:10

1 Answer 1

1

The <apex:inputCheckBox> tag's value attribute takes object values referenced from controller. It should be of datatype Boolean.

But i can see all of your variables are of datatype String. Please change them to

public Boolean Good_with_Cats_c{get;set;}    
public Boolean Active_c{get;set;}
public Boolean HighNeed_c{get;set;}    
public Boolean kid_friendly_c{get;set;}
public Boolean Non_shedder_c{get;set;}    
public Boolean Predatory_Tendencies_c{get;set;}

and in your constructor initialize them to false.

You need to change your query to use the boolean variables as bind variables by using : next to it.

query='SELECT Name,ID,Good_with_Cats__c,Pet_ID__r.Gender__c,Pet_ID__r.Height__c,Pet_ID__r.Name__c,Pet_ID__r.pet__c,Pet_ID__r.Pet_Photo__c,Pet_ID__r.Status__c FROM Characteristics__c where Good_with_Cats__c=:Good_with_Cats_c or Active__c=:Active_c or HighNeed__c=:HighNeed_c or kid_friendly__c=:kid_friendly_c or Non_shedder__c=:Non_shedder_c or Predatory_Tendencies__c=:Predatory_Tendencies_c';

Hope it helps.

3
  • but i changed too boolean now also i am getting the error System.QueryException: value of filter criterion for field 'Good_with_Cats__c' must be of type boolean and should not be enclosed in quotes
    – user31850
    May 25, 2016 at 18:33
  • Updated my answer to include how to use apex variables directly in SOQL as bind variables. Take a look. May 25, 2016 at 18:53
  • how to get the value of checked checkbox
    – user31850
    May 26, 2016 at 6:14

You must log in to answer this question.