Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
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
3 answers
  1. May 11, 2015, 12:59 PM
    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

     
Loading
0/9000