Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks for the reply.... I actually wanted to display live count eg. if a checkbox is checked it should display on the visual force page count = 1 and when deselected then it should display zero....
Controller class: public class CountLiveController { public List<Account> acList{get;set;} public List<AccountWrapper> wrapList{get;set;} public List<AccountWrapper> selectedWrap{get;set;} public Integer Count{get;set;} public CountLiveController() { acList=new List<Account>(); selectedWrap = new List<AccountWrapper>(); acList=[Select name from Account limit 10];// Show number of accounts as per requirement wrapList=new List<AccountWrapper>(); for(Account a:acList) { AccountWrapper aw=new AccountWrapper(a); wrapList.add(aw); } System.debug('>>wrapList'+wrapList); }
public class AccountWrapper{ public Boolean selected{get;set;} public Account acc{get;set;} public AccountWrapper(Account a) { acc=a; selected=false; } }
@Deepali Kulshrestha How would you modify this so instead of a count you had a sum / aggregation of a currency field on the account record? e.g. live amount instead of live count.
Greetings to you!
Try this:
Also, please refer to the below links which might help you further with the above requirement.
https://salesforce.stackexchange.com/questions/116367/how-to-count-the-number-of-records-selected-through-a-checkbox
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
I actually wanted to display live count
eg. if a checkbox is checked it should display on the visual force page count = 1 and when deselected then it should display zero....
Please do try this code below and you will surely be able to display live count of selected accounts on your vf page.
Vf page:
<apex:page controller="CountLiveController">
<script>
function test()
{
console.log('>>yes');
methodOneInJavascript();
}
</script>
<apex:form id="frm" >
<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="frm"/>
<apex:pageBlock title="Accounts">
<apex:pageBlockTable value="{!wrapList}" var="a">
<apex:column headerValue="Select Account">
<apex:inputCheckbox value="{!a.selected}" onchange="test();"/>
</apex:column>
<apex:column headervalue="Account Name" value="{!a.acc.name}"/>
</apex:pageBlockTable>
<apex:pageBlockSection>
Live Count::: {!Count}
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller class:
public class CountLiveController {
public List<Account> acList{get;set;}
public List<AccountWrapper> wrapList{get;set;}
public List<AccountWrapper> selectedWrap{get;set;}
public Integer Count{get;set;}
public CountLiveController()
{
acList=new List<Account>();
selectedWrap = new List<AccountWrapper>();
acList=[Select name from Account limit 10];// Show number of accounts as per requirement
wrapList=new List<AccountWrapper>();
for(Account a:acList)
{
AccountWrapper aw=new AccountWrapper(a);
wrapList.add(aw);
}
System.debug('>>wrapList'+wrapList);
}
public class AccountWrapper{
public Boolean selected{get;set;}
public Account acc{get;set;}
public AccountWrapper(Account a)
{
acc=a;
selected=false;
}
}
public void methodOne()
{
selectedWrap.clear();
for(AccountWrapper wrap:wrapList)
{
if(wrap.selected==true)
{
selectedWrap.add(wrap);
}
Count=selectedWrap.size();
system.debug('::::'+selectedWrap);
}
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
How would you modify this so instead of a count you had a sum / aggregation of a currency field on the account record?
e.g. live amount instead of live count.
Many thanks