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.

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
Requirement - Selected records or multiple records at a time.
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi 

Can you describe the Visualforce, Does the vf page contain a list of Account with a check box. When we check the check boxes of Account and click button then the related Accounts should be updated ? Is this the way you were asking about?

Just a clarification.

Thanks.
Pankaj Yadav 16Pankaj Yadav 16
Requirement;
User can select all records at once, and can be perform manual selection based on business requirement.
After record selection user needs to click on any button (Activate, Inactivate)
When Activate button is clicked then it activate all the selected account.
When Deactivate button is clicked then it deactivate all the selected account. After the execution it will redirect to the Page (Home).
public class ActiveAccAss2
{
private integer totalRecs = 0;
private integer OffsetSize = 0;
private integer LimitSize= 5;

public List<Account> AccountsOrigList {get;set;}
public List<AccountWrapper> AccountsWrappersList {get;set;}
    
public ActiveAccAss2()
{
totalRecs = [select count() from account];
}
    
 ApexPages.StandardSetController setCon {
        get {
            setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
            [SELECT  Name, ID, Phone,Active__c FROM Account LIMIT :LimitSize]));
			
         return setCon;
        }
        set;
    }
    
    public List<AccountWrapper> getAccountList() {
        if (AccountsOrigList == null)
        { AccountsOrigList = setCon.getRecords(); 
          AccountsWrappersList = new List<AccountWrapper>();
          for (Account avar : AccountsOrigList)
          {
            AccountsWrappersList.add(new AccountWrapper(avar,false));
          }
        }  
        
        return AccountsWrappersList ;
    }
    
    
    public class AccountWrapper
    {
        public Account acc {get; private set;}
        public Boolean DeleteInd {get; set;}
      
        public AccountWrapper(Account a , Boolean dInd)
          {
           DeleteInd = dInd;
           acc = a;
          }
    }
    
    public Pagereference SaveAcc()
     {
        List<Account> AccountsToDelete = new List<Account>();
        List<Account> AccountsToUpsert = new List<Account>();  
 
        for (AccountWrapper avar : AccountsWrappersList )
        {
            if (avar.DeleteInd == True)
                {
                 if (avar.acc.id != null)               
                    {System.Debug (avar.acc.name);
                    AccountsToDelete.add(avar.acc);}
                    
                }
            else
                {AccountsToUpsert.add(avar.acc); }            
        }
      
       delete AccountsToDelete; 
       upsert AccountsToUpsert;
              
       AccountsOrigList = [SELECT Name, ID FROM Account] ;
       AccountsWrappersList = new List<AccountWrapper>();
       for (Account avar : AccountsOrigList)
          {
            AccountsWrappersList.add(new AccountWrapper(avar,false));
          }
       
      PageReference secondPage = Page.Thankyou;
      secondPage.setRedirect(true);
      return secondPage; 

         
     }
 
 
public Account lastGoal {get; private set;}

  public void deleteLast()
    {
        delete lastGoal;
    }
    
   
public void FirstPage()
{
OffsetSize = 0;
}
    
public void previous()
{
OffsetSize = OffsetSize-LimitSize;
}
    
public void next()
{
OffsetSize = OffsetSize + LimitSize;
}
    
public void LastPage()
{
OffsetSize = totalrecs-math.mod(totalRecs,LimitSize);
}
    
public boolean getprev()
{
if(OffsetSize == 0)
return true;
else
return false;
}
    
public boolean getnxt()
{
if((OffsetSize + LimitSize) > totalRecs)
return true;
else
return false;
}     
}
<apex:page controller="ActiveAccAss2" >
    <apex:form >
        <apex:pageBlock id="details">
             <apex:pageBlockTable value="{!AccountList}" var="a" id="AccDMLTable">
             <apex:column headerValue="S.No">
            <apex:inputCheckbox value="{!a.DeleteInd}" rendered="true"/>
            </apex:column>
            <apex:column headerValue="Account Name" >
            <apex:outputField value="{!a.acc.Name}"/>
            </apex:column>
            <apex:column value="{!a.acc.ID}"/>
            <apex:column value="{!a.acc.Phone}"/>
            <apex:column value="{!a.acc.Active__c}"/>
           
            </apex:pageBlockTable>
            
            <apex:commandButton value="Delete" action="{!SaveAcc}" reRender="AccDMLTable"/>    
            <apex:commandButton value="Activate/deactivate" reRender="AccDMLTable"/>            
       
            <apex:pageblockButtons >
                <apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!prev}"/>
                <apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
                <apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>
                <apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/>"
            </apex:pageblockButtons>
        </apex:pageBlock>
        </apex:form>
</apex:page>