---
schema_version: "1"
id: 6da3953c116bf3a34d3c4444459ddbdaaaaa6df9fff88468edb024406eaf3106
title: Pagination with a List Controller
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/controller-std/pages-controller-sosc-pagination.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-controller-sosc-pagination.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: c051275e3bd6dceb2890e0f97361178ede46c067ea4c59a6b0dccf987972eb0d
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# 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.

**note:** 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](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-controller-sosc-list-views.md).

```apex
<apex:page standardController="Account" recordSetvar="accounts">
    <apex:pageBlock title="Viewing Accounts">
        <apex:form id="theForm">
            <apex:pageBlockSection >
                <apex:dataList var="a" value="{!accounts}" type="1">
                    {!a.name}
                </apex:dataList>
            </apex:pageBlockSection>
            <apex:panelGrid columns="2">
                <apex:commandLink action="{!previous}">Previous</apex:commandlink>
                <apex:commandLink action="{!next}">Next</apex:commandlink>
            </apex:panelGrid>
        </apex:form> 
    </apex:pageBlock>
</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](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/controller/pages-controller-extension.md).

**note:** 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.

