+ Start a Discussion
Qadir KhanQadir Khan 

How to add Checkbox in vf page

public class lonchangeaccount{
        public id aid{get;set;}
        public boolean render{get;set;}
        List<selectoption> options=new List<selectoption>();
        public  List<Contact> lstcont{get;set;}
        public lonchangeaccount(){
                    lstcont=new List<contact>();
        Map<id,List<contact>> maplstcont=new Map<id,List<contact>>();
        public List<SelectOption>  getValues(){
                options.add(new selectOption('--None--','--None--'));
                for(Account acc:[select id,name,(select id,name,email from contacts)from account]){
                    options.add(new selectOption(acc.id,acc.name));
                return options;
        public void  Contactlst(){

VF Page
<apex:page controller="lonchangeaccount">
<apex:form >
         <apex:pageBlock title="Select Account">
         <apex:actionFunction action="{!Contactlst}" name="change"/>
         <apex:selectList value="{!aid}" multiselect="false" size="1" onchange="change();">
                <apex:selectOptions value="{!values}"/>
            <apex:pageBlock title="Related Contacts" >
          <apex:outputPanel rendered="{!render}" id="balu">
              <apex:pageBlockTable value="{!lstcont}" var="c">
                      <apex:column value="{!c.name}"/>
                      <apex:column value="{!c.email}"/>
             <apex:commandButton value="Next"/>

SandhyaSandhya (Salesforce Developers) 
Hi Qadir Khan,

You need to use the wrapper class to add the checkbox in visual force page.

A wrapper or container class is a class, data structure, or an abstract data type whose instances are collections of other objects.It is a custom object defined by Salesforce developer where he defines the properties of the wrapper class. Within Apex & Visualforce this can be extremely helpful to achieve many business scenarios within the Salesforce CRM software.

I suggest you refer below links to know more about it.


Hope this helps you!

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards

Narveer SinghNarveer Singh
Hi Qadir,

To add Check box in vf you can use below code :

    <apex:facet name="header">Your Header</apex:facet>
        <apex:inputCheckbox value="{!c.yourVarriable}" />

you can use wrapper class as :

public class varWrapper {
    public Boolean VarriableName{get;set;}

And your controller will be : 

public with sharing class checkboxController {
   public List<varWrapper> wrapperList{get;set;}
   public List<varWrapper> getCheckBoxVarriable() {
        wrapperList = new List<varWrapper>();
        String query =  'SELECT Id,isRequired From Account'         
        for(Account acc :  Database.query(query1)){
            varWrapper twrap = new varWrapper();
    return wrapperList;

Hope this helps you!

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution.

Best Regards
Priyank KotakPriyank Kotak
Hi! Qadir Khan,

To add a column of checkbox in your datatable, just write the below code inside you VFP datatable...

<apex:column headerValue="Select">
                     <apex:inputcheckbox />

Best Regards,
Suraj Tripathi 47Suraj Tripathi 47
Hi Qadir Khan,

You can add checkbox in your page using below line of code.
<apex:inputCheckbox value="{!c.yourValue}" />

If you find your Solution then mark this as the best answer.

Thank you!

Suraj Tripathi