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
Pankaj Yadav 16Pankaj Yadav 16 

I have craeated one check box field in Account object and i want to create a button in visualforce page to activate and detivate the check box option. Please help slected

Requiremnet - Selected records or multiple records at a time.
Pramod Kumar MPramod Kumar M
Pankaj,
Try this below VF Page and ControllerExtension  to Select Multiple Accounts and Update the CheckBox.


User-added image
<apex:page StandardController="Account" extensions="checkboxtest" showHeader="false" setup="false" sidebar="false">
  <apex:form >
  <apex:pageBlock >
  <apex:pageBlockButtons >
  <apex:commandButton value="Check" action="{!myCheck}" />
  <apex:commandButton value="UnCheck" action="{!myUnCheck}"/>
  </apex:pageBlockButtons>
   <apex:pageBlockSection columns="1" collapsible="false">        
  
                <apex:pageBlockTable value="{!show}" var="e" title="show" >
                    <apex:column headerValue="Select">
                        <apex:inputCheckbox value="{!e.check}"/>
                    </apex:column>                    
                    <apex:column headerValue="Account Name">
                        <apex:commandLink value="{!e.acc.Name}"/>
                    </apex:column>
                    <apex:column headerValue="Phone">
                        <apex:commandLink value="{!e.acc.phone}"/>
                    </apex:column>
                     <apex:column headerValue="Check Box">
                        <apex:outputField value="{!e.acc.Match_Billing_Address__c}"/>
                    </apex:column>
                </apex:pageBlockTable>
            
  </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form> 
</apex:page>
Extension Controller : 
public with sharing class checkboxtest {
List<AccAccount> accList;
    Boolean allbool;
    ApexPages.StandardController controller;
    
    public checkboxtest(ApexPages.StandardController con) {
        controller = con;
        accList = new List<AccAccount>();
        actids = new Set<Id>();
      }
    
     public class AccAccount  {
        public Account acc{get;set;}
        public boolean check{get;set;}
        
        public AccAccount(Account a, boolean boo){
            acc = a; 
            check = boo; 
        }
    }
public List<AccAccount> getShow(){ 
      if(accList.isEmpty()){
          for(Account coObj:[select id,name,phone,Match_Billing_Address__c from Account limit 1000]) {
                       accList.add(new AccAccount(coObj,allbool));    
                               }
        }
        return accList;
    }
    public void myCheck(){     
     List<Account> acLst = new List<Account>();
     for(AccAccount accObj : accList) {
            if(accObj.check != false){
                accObj.acc.Match_Billing_Address__c = true;
                acLst.add(accObj.acc); 
                
                 accObj.check = false;
         }            
        }
        update acLst;    
    }
        public void myUnCheck(){     
     List<Account> acLst = new List<Account>();
     for(AccAccount accObj : accList) {
            if(accObj.check != false){
                accObj.acc.Match_Billing_Address__c = false;
                acLst.add(accObj.acc); 
                
                 accObj.check = false;
         }            
        }
        update acLst;    
    }
 }

Hope This helps..!!