[SalesForce] Using Standard List Controller page Button in related List

I have a Master Object "Job Req", and a detail object "Application"

In a "Job Req" record, i need to put a button in "Applications" related list, that (for now) does something simple, like just open a VF page that displays the Applications that were selected in related list.

I will later expand on that myself. Right now i am having issue passing the selected records to the VF page.

This is what i have done –

Created a List button on Application object, that opens a VF Page

Added that Button to the Applications Related List on Job Req page layouts

Now When i select some records from Application Related List, and click on the button, i expect it to show names of just those applications. But somehow, it shows whole bunch of records. Instead of showing selected records, it shows some set of records that i don't even know

Selecting singel record

Here is the output, which shows some bunch of records, instead of showing just 1 i selected-
Output shows some set of records here

Here is my VF page code

<apex:page standardController="ts2__Application__c" recordSetVar="selectedApplications">
  <apex:pageBlock >
    <apex:pageBlockTable value="{!selectedApplications}" var="a">
        <apex:column value="{!a.name}"/>       
    </apex:pageBlockTable>
  </apex:pageBlock>
</apex:page>

If anyone has any clue how to get selected records working from a related list, please let me know (using Standard set controllers). I don't want to use a javascript button that passes IDs of selected records. I already have that working, but it has limitations on how many IDs can be passed via URL parameter (most browsers crap at url length of 2000 characters).

Best Answer

You can use controller extension with StandardSetController. The getSelected() method of StandardSetController returns the selected records.

Visualforce

<apex:page standardController="ts2__Application__c" recordSetVar="selectedApplications" extensions="ApplicationExtn">
  <apex:pageBlock >
    <apex:pageBlockTable value="{!selectedApplications}" var="a">
        <apex:column value="{!a.name}"/>       
    </apex:pageBlockTable>
  </apex:pageBlock>
</apex:page>

Controller Extension

public class ApplicationExtn {
    public List<ts2__Application__c> selectedApplications {get;set;}
    private ApexPages.StandardSetController controller;
    private Set<Id> appIds = new Set<Id>();

    public ApplicationExtn(ApexPages.StandardSetController controller){
        this.controller = controller;
        selectedApplications = controller.getSelected();
}

For more information, refer StandardSetController Class