You need to sign in to do that
Don't have an account?
gotherthanthou
GetSelected() always returning 0
I'm hoping someone can tell me what I'm doing wrong here. Whenever I press the "Count Selected" button, this is what shows up in the debug log no matter how many records I have manually selected on the displayed page:
[20]|DEBUG|xyzzy: Num Selected 0
Here is the page, followed by the controller. Obviously these are slimmed down from the actual page and controller I am working on.
<apex:page standardController="Account" recordSetVar="true" extensions="aaaDonNotPackageController" id="page"> <apex:pageBlock mode="mainDetail" id="PB" > <apex:form id="form"> <apex:commandButton value="Count Selected" action="{!CountSelected}" /> </apex:form> <apex:enhancedList id="list" type="Account" height="570" width="1200" rowsPerPage="25" customizable="true"/> </apex:pageBlock> </apex:page>
global with sharing class aaaDonNotPackageController { public ApexPages.StandardSetController setController; // Constructor public aaaDonNotPackageController (ApexPages.StandardSetController controller) { Initialize(controller); } // placed outside constructor for easier debugging private void Initialize (ApexPages.StandardSetController controller) { setController = controller; } public void CountSelected() { List<sObject> selAccts = setController.getSelected (); system.debug ('xyzzy: Num Selected ' + string.valueof(selAccts.size())); } }
The StandardSetController is meant to be used with a Custom List Button override:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_massupdate.htm?SearchType=Stem&Highlight=getSelected
If you create a custom list button, it should show up at the top of your enhanced list, and then this should work as you are expecting.
If anyone else is looking for this too, this idea might be of interest to you:
https://success.salesforce.com/ideaView?id=08730000000g6wLAAQ