I have standard object tab and added object button to VisualForce page on it. The VF have very simple code:

    <apex:page standardController="Contract" recordSetVar="Contract">
     <apex:pageBlock title="The id of the Contract Standard object">
        <apex:pageBlockTable value="{!Contract}" var="a">
            <apex:column value="{!a.Status}"/>
            <apex:column value="{!a.ContractNumber}"/>

But when i click the button the VF page display always the last record instead of selected one: enter image description here

enter image description here

Is there a way to make the VF page display selected record (or records, could be more than one selected) instead of last one?

  • 1
    What happens if you use {!selected} for the value parameter of the pageBlockTable? It's been years since I played with this stuff but when you use a StandardSetController in Apex it has a separate list of selected records, seems odd that you've only got one and the wrong one though.
    – Matt Lacey
    Dec 15, 2021 at 17:27
  • Thanks Matt, {!selected} is exactly what i needed.
    – Thimotty
    Dec 15, 2021 at 17:31

1 Answer 1


StandardSetControllers maintain two lists of records, one of which is the set of selected records, and this information can come from a list view as you desire.

Swapping out the name of your recordSetVar in the page block table for {!selected} (which calls the Apex method getSelected() from the StandardSetController class in the background) should do the trick:

   <apex:pageBlockTable value="{!selected}" var="a">
       <apex:column value="{!a.Status}"/>
       <apex:column value="{!a.ContractNumber}"/>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .