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
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.

Regards,
Alok
ManojjenaManojjena
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 
 
 If(checkValue==true){
 accListToDiaplay=[SELECT id ,Name FROM Account WHERE is_active__C =TRUE  LIMIT 10000];
 }else{
 accListToDiaplay=[SELECT id ,Name FROM Account LIMIT 10000 ];
 }

Let me know any issue .

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

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BFqzIAG

You can use following code 

PAGE
<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>
          
           <apex:pageblockTable value="{!accountList}" var="wrapRec" rendered="{!selectedList}">
               <apex:column value="{!wrapRec.Name}" />
               <apex:column value="{!wrapRec.Id}"/>               
          </apex:pageblockTable>
        </apex:outputPanel>      
    </apex:pageBlock>
    </apex:form>
</apex:page>

CONTROLLER
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];
		}else{
			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