0

How to have multiple custom input checkboxes in the apex - salesforce?

Apex

public class actionSupportController {
    public List<PCS_Household__c> lstQuery{get;set;} 
    public List<PCS_Household__c> OnlstQuery{get;set;}
    public string ID_c{get;set;}      
    public string test{get;set;}

    public List<wpetwizardcontroller> chrcs{get;set;}
    public List<Characteristics__c> selctchr{get;set;}
    public List<Pets_Information__c> selctpet{get;set;}

    public List<wpetwizardcontroller> getchrc(){
        if(chrcs==null){
            chrcs=new List<wpetwizardcontroller>();
            for(Characteristics__c chrc:[SELECT 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=:true]){
                chrcs.add(new wpetwizardcontroller(chrc, false));
            }
        }
        return chrcs;
    }

    Public PageReference chk(){
        chrcs=new List<wpetwizardcontroller>();
        for(Characteristics__c chrc:[SELECT 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=:true]){
            chrcs.add(new wpetwizardcontroller(chrc, false));
        }
        return null;
    }

    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('==lstQuery=='+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('==Query=='+Query);
        lstQuery=Database.query(Query);
        system.debug('==lstQuery=='+lstQuery);
    }

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

    public PageReference nextpage() {

        upsert OnlstQuery;

        return Page.cc;
    }

    public class wpetwizardcontroller {
        public Characteristics__c chrc {get;set;}
        public boolean selectd {get;set;}
        public wpetwizardcontroller(Characteristics__c chrc, Boolean selected) {
            this.chrc = chrc;
            this.selectd = false;
        }
    }
}

Visualforce

<apex:page Controller="actionSupportController">
    <apex:form >
        <apex:pageBlock >
            Household Name: <apex:inputText value="{!ID_c}"/>
        </apex:pageBlock>
        <apex:pageBlock title="Characteristics Information">
            <apex:pageBlockTable value="{!chrcs}" var="eachpet">
                <apex:column value="{!eachpet.chrc.Name}" />
                <apex:inputCheckbox value="{!eachpet.selectd}" />
            </apex:pageBlockTable>

            <br/><apex:commandButton value="Search" action="{!getchrc}" rerender="sblck"/>
        </apex:pageBlock>
        <apex:outputPanel id="sblck">
            <apex:pageBlock title="Search Results">
                <apex:pageBlockTable value="{!selctpet}" var="eachpet">
                    <apex:column value="{!eachpet.Name}"/>
                    <apex:column value="{!eachpet.Gender__c}"/>
                    <apex:column value="{!eachpet.Height__c}"/>
                    <apex:column value="{!eachpet.Name__c}"/>
                    <apex:column value="{!eachpet.pet__c}"/>
                    <apex:column value="{!eachpet.Pet_Photo__c}"/>
                    <apex:column value="{!eachpet.Status__c}"/>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:outputPanel>
        <apex:commandButton value="Request Adoption"/>
    </apex:form>
</apex:page>
3
  • 1
    Can you please explain your scenario. Are you looking to have multiple check box for each record.
    – Anu
    May 23, 2016 at 9:53
  • according to the selected check boxes values have to be return
    – muralimano
    May 23, 2016 at 10:05
  • i have used the wrapper class .bind the custom object and the Boolean value. but failed to retrieve
    – muralimano
    May 23, 2016 at 10:07

1 Answer 1

2

So you can use wrapper class. As in your code you are using the wrapper class you just need to use it in loop.

<apex:pageBlockTable value="{!chrcs}" var="eachpet">
   <apex:column value="{!eachpet.chrc.Name}" />
   <apex:inputCheckbox value="{!eachpet.selectd}" />
</apex:pageBlockTable>

Make these changes to your Apex

public class wpetwizardcontroller {
    public Characteristics__c chrc {get;set;}
    public boolean selectd {get;set;}
    public wpetwizardcontroller(Characteristics__c chrc, Boolean selected) {
        this.chrc = chrc;
        this.selectd = false;
    }
}


chrcs.add(new wpetwizardcontroller(chrc, false));

This may help you to fix your issue.

13
  • i used this but the checkbox are not visible.
    – muralimano
    May 23, 2016 at 10:22
  • now also checkbox are not visible.
    – muralimano
    May 23, 2016 at 10:29
  • Can you try it now ?
    – Anu
    May 23, 2016 at 10:37
  • i am getting an error "Constructor not defined: [actionSupportController.wpetwizardcontroller].<Constructor>(Characteristics__c)" in line 15
    – muralimano
    May 23, 2016 at 10:37
  • no anu again i am getting the same error.
    – muralimano
    May 23, 2016 at 10:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .