function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Multi-Record Selection - Select All

When you check the top box on a page with Multi-Record Selection, it selects/deselects only the records currently displayed on the page.  So if there are 50 records in the view but only 25 records per page, it only affects the 25.


How would I go about implementing a "Select All" link or button?

Chamil MadusankaChamil Madusanka


Try this example.


<apex:page controller="Checkbox_Class" Tabstyle="Account">
    <apex:form >
        <apex:pageBlock Title="Accounts with CheckBoxes">
            <apex:pageBlockSection Title="List of Available Accounts">
                <apex:dataTable value="{!accounts}" var="a" columnswidth="50px,50px" cellpadding="4" border="1">
                    <apex:column >
                        <apex:facet name="header"> <apex:inputCheckbox >
                            <apex:actionSupport event="onclick" action="{!GetSelected}" onsubmit="checkAll(this)" rerender="Selected_PBS"/>
                        <apex:inputCheckbox value="{!a.selected}" id="checkedone">
                        <apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_PBS"/></apex:inputCheckbox>
                    <apex:column headervalue="Account Name" value="{!a.acc.Name}" />
                    <apex:column headervalue="Account Number" value="{!a.acc.AccountNumber}" />
                    <apex:column headervalue="Phone" value="{!a.acc.Phone}" />

            <apex:pageBlockSection Title="Selected Accounts" id="Selected_PBS">
                <apex:dataTable value="{!SelectedAccounts}" var="s" columnswidth="50px,50px" cellpadding="4" border="1">
                    <apex:column headervalue="Account Name" value="{!s.Name}" />
                    <apex:column headervalue="Account Number" value="{!s.AccountNumber}" />
                    <apex:column headervalue="Phone" value="{!s.Phone}" />

        function checkAll(cb)
            var inputElem = document.getElementsByTagName("input");
            for(var i=0; i<inputElem.length; i++)
                inputElem[i].checked = cb.checked;


public class Checkbox_Class

    List<accountwrapper> accountList = new List<accountwrapper>();
    List<Account> selectedAccounts = new List<Account>();

    public List<accountwrapper> 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<Account> 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;

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.


Chamil's Blog

Is it possible to do it in Standardcontroller ? I have the same problem
I want to select all account in the given view not just one page.