I'm very new to SFDC and now I'm trying to implement pagination using offset values. But I'm getting this error: Return type of an Apex action method must be a PageReference. Found: visualforce.el.VisualforceArrayList

I've built with the help of this tutorial link

Here is my complete code for the same. Please have a look


<apex:page controller="NewContactPaginationCtrl" action="{!getContacts}" >
    <apex:pageBlock title="Contact Table With Pagination">
        <apex:pageBlockTable value="{!cList}" var="c">
            <apex:column value="{!c.id}" />
            <apex:column value="{!c.name}" />
            <apex:column value="{!c.email}" />
            <apex:outputPanel id="myButtons">
                    <apex:commandButton action="{!Previous}" title="Previous" value="< Previous" disabled="{!disablePrevious}" reRender="myPanel,myButtons"/>        
                    <apex:commandButton action="{!Next}" title="Next" value="Forward >" disabled="{!disableNext}" reRender="myPanel,myButtons"/>


public class NewContactPaginationCtrl {
    Private Integer counter=0;
    private integer list_size=5;
    public integer total_size;
    public NewContactPaginationCtrl(){
        total_size = [select count() from Contact];
    public Contact[] getContacts(){
        try {
            Contact[] contacts = [
                email FROM
                LIMIT :list_size
                OFFSET :counter
            return contacts;
        } catch(QueryException e) {
            return null;
    public PageReference Previous(){
        counter -= list_size;
        return null;
     public PageReference Next(){
        counter += list_size;
        return null;
    public Boolean getDisablePrevious() {
            return false;
            return true;
    public Boolean getDisableNext(){
        if(counter+list_size < total_size){
            return false;
           return true;

1 Answer 1

<apex:page controller="NewContactPaginationCtrl" action="{!getContacts}" >

This is attempting to tell Visualforce that you want to (possibly) redirect using the action parameter. This is incorrect, and shouldn't be there.

<apex:page controller="NewContactPaginationCtrl">

    <apex:pageBlockTable value="{!cList}" var="c">

cList doesn't exist. It should be contacts:

    <apex:pageBlockTable value="{!contacts}" var="c">

A getX method can be bound to an attribute, and the get is removed. This is called a getter method.

The comparison operators already return a true/false value, so you don't have to. For example:

public Boolean getDisableNext(){
  return counter+list_size >= total_size;

You should look at the ApexPages.StandardSetController. It provides all the same functionality you have here, but supports up to 10,000 rows (your code would be limited to 2000 plus page size, as OFFSET has a limit of 2000).

  • Thank you so much, It worked! I learnt so much from you. Appreciated your help :-) Jun 21, 2021 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .