+ Start a Discussion
praveen naraharisettypraveen naraharisetty 

show active account list on my vf page by checkbox

i have is_active__C checkbox on account object. so my requirment is on visualforce page i want to take one check box as 'show active accounts only'.when ever its checked i want to show active accounts only(which account checked while creating account record).otherwise show all accounts

on vf page i created one chekbok with name show active accounts and have one command button get accounts. if the chekbox is checked i want to show only active accounts
Alok Khandelwal - DamcoAlok Khandelwal - Damco
Bind the Active checkbox on page with a boolean value on the controller. Use this field in the where clause of the Account query to pass true or false to get the desired results.

Your problem should be solved.

Hi Praveen,

Try with below cod eit will hep ! 
Checkbox code needs to add in page 
 <apex:inputCheckbox value="{!checkValue}" />
 //Variable related to checkbox in class
 public String checkValue { get; set; }
 Declare a List<Account> accListToDiaplay{get;set;}
 instantiate inside constructor 
 accListToDiaplay=new List<Account>();
 inside method 
 accListToDiaplay=[SELECT id ,Name FROM Account WHERE is_active__C =TRUE  LIMIT 10000];
 accListToDiaplay=[SELECT id ,Name FROM Account LIMIT 10000 ];

Let me know any issue .

Mudasir WaniMudasir Wani
Hi Praveen,
Here is a similar post.


You can use following code 

<apex:page controller="Account" sidebar="false" extensions="accountExtension">
    <apex:form >
    <apex:inputCheckbox value="{!activeAccountOnly}"/>
	<apex:commandButton value="Show Active Accounts" action="{!showActiveAccounts}" reRender="panelId"/>
    <apex:pageBlock >
        <apex:outputPanel id="panelId">
            <apex:pageblockTable value="{!accountList}" var="wrapRec" rendered="{!normalList}">
               <apex:column value="{!wrapRec.Name}" />
               <apex:column value="{!wrapRec.Id}"/>
           <apex:pageblockTable value="{!accountList}" var="wrapRec" rendered="{!selectedList}">
               <apex:column value="{!wrapRec.Name}" />
               <apex:column value="{!wrapRec.Id}"/>               

public class accountExtension{
	public List<Account> accountList{get;set;}
	public accountExtension(ApexPages.StandardController controller){
		accountList = [SELECT id ,Name FROM Account];
	public boolean activeAccountOnly{get;set;}
	public void showActiveAccounts(){
        accountList = new List<myWrapperClass>();
        normalList = false;
        selectedList = true;
		if(activeAccountOnly == false)
			accountList = [SELECT id ,Name FROM Account WHERE is_active__C =TRUE];
			accountList = [SELECT id ,Name FROM Account];

Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help