Pagination with a List Controller

To add pagination to a Visualforce page that has a list controller, use the next and previous actions.

In this example, a Visualforce page is associated with a standard Account list controller. The page contains two <apex:commandLink> components with action attributes set to {!previous} and {!next}, respectively. When a user clicks one of the links, the associated action is called, and the subset of account records displays on the page.

In the example, the page doesn’t specify a filter in the request, so the page is displayed with the last used filter. For information on using filters with list controllers, see List Views with Standard List Controllers.

Note

1<apex:page standardController="Account" recordSetvar="accounts">
2    <apex:pageBlock title="Viewing Accounts">
3        <apex:form id="theForm">
4            <apex:pageBlockSection >
5                <apex:dataList var="a" value="{!accounts}" type="1">
6                    {!a.name}
7                </apex:dataList>
8            </apex:pageBlockSection>
9            <apex:panelGrid columns="2">
10                <apex:commandLink action="{!previous}">Previous</apex:commandlink>
11                <apex:commandLink action="{!next}">Next</apex:commandlink>
12            </apex:panelGrid>
13        </apex:form> 
14    </apex:pageBlock>
15</apex:page>
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. See Building a Controller Extension.

When you use pagination, an exception is thrown in collections that have modified rows, including rows added through an extension action. In this case, the error messages follow the standard behavior, and they can be displayed on the page. For example, you can use the <apex:pageMessages> or <apex:messages> component to display an error message to the user.

Note