i am new to salesforce. I am facing a problem like i have pageblock table in my visualforce page and i provide checkbox to each and every record so user can delete one or multiple records at a time.Now my requirement is to provide a master checkbox before all record rows means if user selects that all records will be selected to delete.Please provide me a suggestion to implement in my code.I had already working in it,If i post any wrong question please don't flag like bad please help me

My visualforce page code

<apex:page standardController="Experiment__c" extensions="SampleCheckbox" >
    <apex:form >
        <apex:pageBlock title="Experiment Details">
            <apex:pageBlockButtons >
                <apex:commandButton value="Find" action="{!find}" reRender="searchlist"/>
            <apex:pageblockSection >
                <apex:inputfield value="{!Experiment__c.Name}"/>
        <apex:pageBlock id="searchlist" title="Experiment details">
            <apex:pageBlockTable value="{!memlist}" var="mem">
                <apex:column >
                <apex:inputCheckbox value="{!mem.checked}"/>
                <apex:column value="{!mem.expwc.Name}" title="Member Name" />
                <apex:column value="{!mem.expwc.email__c}" title="E-Mail Id"/>
                <apex:column value="{!mem.expwc.mobile__c}" title="mobile"/>
            <apex:pageblockButtons >
                <apex:commandButton value="Delete" action="{!del}" reRender="searchlist"/>

My controller

public class SampleCheckbox {
    public List<Experiment__c> explist{set;get;}
    public List<mem> memlist{get;set;}
    public Experiment__c exp;
    public List<Experiment__c> memdellist; 
    public Boolean checked{set;get;}
    //public Boolean show{set;get;}

    public SampleCheckbox(Apexpages.StandardController controller) {
    public class mem {
        public Experiment__c expwc{get;set;}
        public Boolean checked {get;set;}
        public mem(Experiment__c e,Boolean b) {
    public void find() {
        String nam=exp.Name;
        memlist=new List<mem>();
        if(memlist == null) {
            memlist=new List<mem>();
        String sql='SELECT Name,light_weight__email__c,light_weight__mobile__c FROM 
        Experiment__c WHERE Name LIKE \'%'+nam+'%\'';
        for(Experiment__c e:explist) {
            mem mo=new mem(e,false);
    public void del() {
        memdellist=new List<Experiment__c>();
        for(mem m:memlist) 
                    memdellist=new List<Experiment__c>();      
        delete memdellist;
  • Hi user2185482 -- as a matter of community etiquette, we ask you to format your code so it is not all left-aligned as that is very hard to read
    – cropredy
    Sep 29, 2015 at 1:02

1 Answer 1


Given this component:

<apex:component >

function cvCheckAllOrNone(allOrNoneCheckbox) {

    // Find parent table
    var container = allOrNoneCheckbox;
    while (container.tagName != "TABLE") {
        container = container.parentNode;

    // Switch all checkboxes
    var inputs = container.getElementsByTagName("input");
    var checked = allOrNoneCheckbox.checked;
    for (var i = 0; i < inputs.length; i++) { 
        var input = inputs.item(i);
        if (input.type == "checkbox") {
            if (input != allOrNoneCheckbox) {
                input.checked = checked;

<apex:inputCheckbox onclick="cvCheckAllOrNone(this)" title="Toggle All Rows"/>


you can add a checkbox to the header row of your checkbox column that uses it to check all or none of the checkboxes:

<apex:column >
    <apex:facet name="header">
        <c:CheckAllOrNone />
    <apex:inputCheckbox value="{!mem.checked}"/>

As this runs at the client side it is nice and quick.


You must log in to answer this question.

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