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
gotherthanthougotherthanthou 

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()));                    
    }
}

 

gotherthanthougotherthanthou
PS - getRecords is working as expected.
TheSwamiTheSwami

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.

trmptrmp
So there is no way to use the getSelected method from the StandardSetController class in conjunction with an enhancedList Visualforce component?

If anyone else is looking for this too, this idea might be of interest to you:

https://success.salesforce.com/ideaView?id=08730000000g6wLAAQ
@jpmaria@jpmaria
If the vf page controller always returns 0, no matter how many records have been selected via checkboxes, then the button where we have added the vf page has to be checked. The 'Display checkboxes (for multi-record selection)' has to checked in order to get the selected records count.Image of Display checkboxes option in VF page button