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
Andrey BolkonskyAndrey Bolkonsky 

Visualforce Extension Example from Developer Guide Not Working

I am working through the VF Dev Guide, and on the section on Standard List Controllers, there is an example about using the Extension Attibute that doesn't work at all when put into practice.

It shows this VF page
<apex:page standardController="Account" recordSetVar="accounts"
extensions="MyControllerExtension">
  <apex:pageBlock >
    <apex:pageBlockTable value="{!accounts}" var="acc">
      <apex:column value="{!acc.name}"/>
    </apex:pageBlockTable>
  </apex:pageBlock>
</apex:page>

and this class for the Extrension Attribute
public with sharing class MyControllerExtension {
    private ApexPages.StandardSetController setController;
    public MyControllerExtension(ApexPages.StandardSetController setController) {
        this.setController = setController;
        Account [] records = [SELECT Id, Name FROM Account LIMIT 30];
        setController.setSelected(records);
    }
}
However, this is not the set of records that is displayed on the page when you save it. I messed around with the query a few times to see if I could get it to work putting in different condisions but it never shows the set of records on the resulting page.

I literally copy pasted the method out of the the Book so I feel like it is something wrong with the code they provided. Does anyone know why this isn't working? Please this is driving me crazy that it isn't functioning right?

Thanks
SwethaSwetha (Salesforce Developers) 
HI Andrey,
I ran the code snippet you provided and it returns a list of 30 accounts. Are you seeing any errors? You can add system.debug statements to narrow down where the issue lies. What is the expected vs actual output? Thanks