+ Start a Discussion

Selected Records from List view gives empty list even though records are selected if the List view button is clicked for the first time

Visualforce page:

<apex:page standardController="Member__c" extensions="MemberExt" recordSetVar="Member">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!memList}" var="M">
            <apex:column value="{!M.Name}"/>
            <apex:column value="{!M.Age__c}"/>
Apex Controller:
public class MemberExt {
    public List<Member__c> memList {get;set;}
    private ApexPages.StandardSetController standardController;
    private Set<Id> memIds = new Set<Id>();
    public MemberExt(ApexPages.StandardSetController standardController){
        this.standardController = standardController;
        memList = new List<Member__c>();
        for (Member__c mem : (List<Member__c>)standardController.getSelected()){
        memList = [SELECT Name, Age__c FROM Member__c WHERE ID IN: memIds];
Custom Button:
User-added image
User-added image

User-added image

have you seen a problem where the very first time through, the getSelected returns empty even though selections have been made...?

You can observe this situation by following below steps:
i) Login as user
ii) Go to the tab, Select the list view and Click on "Go" button to show the list view of all the records
iii) Select all the records and click on the custom list view button that redirects to visualforce page.
iv) Now, even though records have been selected, my page shows empty. This can be observed only the user didn't navigated to any other visualforce page after logging in.
If the user navigates any of the visualforce page after logging in, then the selected records shows properly without any issues. Is there anyway to make sure selected records are shown even when this is the first visualforce page that user navigates to.?

Thanks in advance.
See if the below post gives any clue