+ 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