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
Lu Zhang 10Lu Zhang 10 

Why this code is displaying only 20 records instead of all?

The below is my code. Question is why this is displaying 20 account records instead of all? 

<apex:page standardController="Account" recordSetVar="accounts">
   <apex:pageBlock title="Accounts">
       <apex:pageBlockTable value="{!accounts}" var="a" rows="1000">
       <apex:column headerValue="Name">
        <apex:outputLink value="/{!a.Id}"> {!a.name} </apex:outputLink>
        </apex:column>
       </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>
Dutta SouravDutta Sourav
Hi Lu,

Standard Controller by default only shows the first 20 records that match your filter criteria,
Pagination allows  to let people access more than those first 20 records, or perhaps more records per page than just 20.

Add this following Code under <apex:form>
<apex:panelGrid columns="2" >
         <apex:CommandLink value="Previous" Action="{!previous}"/>
         <apex:CommandLink value="Next" Action="{!Next}"/>
</apex:panelGrid>

Hope this helps!

Best Regards,
Sourav.

 
SandhyaSandhya (Salesforce Developers) 
Hi Zhang,

By default, a list controller returns 20 records on the page. To control the number of records displayed on each page, use a controller extension to set the pageSize. For information on controller extensions, please refer below link.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_pagination.htm​
 
Below is the code which displays all the accounts.

VFPage
--------------
<apex:page standardController="Account" recordSetVar="accounts" extensions="ext1">
   <apex:pageBlock title="Accounts">
       <apex:pageBlockTable value="{!accounts}" var="a" rows="1000">
       <apex:column headerValue="Name">
        <apex:outputLink value="/{!a.Id}"> {!a.name} </apex:outputLink>
        </apex:column>
       </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>
Controller
-------------
public with sharing class ext1 {
    ApexPages.StandardSetController controller;    

    public ext1(ApexPages.StandardSetController controller) {
        this.controller = controller;        
    controller.setPageSize(controller.getResultSize());


    }

}

Please accept my solution as Best Answer if my answer was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya

 
Sanam Karki 5Sanam Karki 5
For anyone struggling with this: 

The standard controller picks up the most recently used list views. Make sure to first view the list view that has the desired filter on and access the visualforce page. 

Thanks. 
Sanam.