How to get selected records from list view in Salesforce?

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:


1 comment:

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


Sharing is Caring!!! Share this with your friends!!!

submit to reddit