Home SALESFORCEAPEX Checkbox in DataTable
Displaying the check box in a data table or page block table is a general requirement in every project. with the help of wrapper class we can display the checkboxes in a data table. For the select all checkbox we need to add small javascript so that if we select the header checkbox it will select all the checkboxes.
Apex Class:

public class Checkbox_Class  { 
    List accountList = new List();
    List selectedAccounts = new List();       
    public List getAccounts()  {
        for(Account a: [select Id, Name, AccountNumber, Phone from Account limit 5])
        accountList.add(new accountwrapper(a));
        return accountList;
    public PageReference getSelected()   {
        for(accountwrapper accwrapper: accountList)
        if(accwrapper.selected == true)
        return null;
    public List GetSelectedAccounts()  {
        return selectedAccounts;
        return null;
    public class accountwrapper  {
        public Account acc{get; set;}
        public Boolean selected {get; set;}
        public accountwrapper(Account a)
            acc = a;
            selected = false;

VisualForce Page:


Demo : https://sfdevforce-developer-edition.na12.force.com/vfCheckbox

You may also like

Leave a Comment