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

Pagination! What am I doing wrong?

I am following the wiki post on pagination to try and display results of a list view.


Here is my page code:



<apex:page standardController="Case" extensions="CaseListController" recordSetVar="cases" tabstyle="trouble_tickets__tab"> <apex:form id="theForm"> <apex:pageBlock title="Cases Home"> <b>You are viewing {!$User.FirstName} {!$User.LastName}'s Open and Closed Trouble Tickets</b> </apex:pageBlock> </apex:form> <apex:form > <apex:pageBlock id="pb1"> <apex:pageBlockButtons location="top"> <apex:commandButton action="/apex/CustomerPortalNewCase" value="Create New Case" id="newCaseButton"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!cases}" var="c" id="c_table"> <apex:column headervalue="Case Number"> <apex:outputLink value="/{!c.Id}" target="_self">{!c.casenumber}</apex:outputLink> </apex:column> <apex:column headervalue="Subject"> <apex:outputLink value="/{!c.Id}" target="_self">{!c.subject}</apex:outputLink> </apex:column> <apex:column headervalue="Created By"> <apex:outputField value="{!c.createdbyid}"/> </apex:column> <apex:column headervalue="Priority"> <apex:outputField value="{!c.priority}"/> </apex:column> <apex:column Value="{!c.status}" style="{!IF(c.Status='New', 'color:brown;font-weight: bold',IF(c.Status='In Progress', 'color:green;font-weight: bold',IF(c.Status='On Hold','color:red;font-weight: bold',IF(c.Status='Get Acceptance','color:blue;font-weight: bold',IF(c.Status='Closed','color:clack;font-weight: bold','color:grey')))))}"/> <apex:column headervalue="Created By"> <apex:outputField value="{!c.createdbyID}"/> </apex:column> <apex:column headervalue="Case Contact"> <apex:outputField value="{!}"/> </apex:column> <apex:column headervalue="Created Date"> <apex:outputField value="{!c.createddate}"/> </apex:column> </apex:pageBlockTable> <apex:commandLink action="{!Prev}" rendered="{!showprev}"><font color="blue">Previous</font></apex:commandLink> <apex:commandLink action="{!Next}" rendered="{!shownext}"><font color="blue">Next</font></apex:commandLink> </apex:pageBlock> <p align="center"><b><apex:outputtext rendered="{!NOT(ISNULL(Case))}" value="Your search criteria returned {!CasList_Size} record(s)"/></b></p><br/> <apex:pageBlock > <apex:pageBlockSection > <c:CaseQuickTipsGuideComponent /> <c:CaseAttachmentsInstructions /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 and here is my controller:


public class CaseListController { public CaseListController(ApexPages.StandardSetController controller) { } List<Case> CasList = new List<Case>(); List<Case> CasList_Next = new List<Case>(); Integer next = 20, count = 20; boolean shownext, showprev; Public void Search() { try { CasList = [select Id, CaseNumber, Subject, CreatedById, Priority, Status, Contact.Name, Account.Name, CreatedDate From Case Order By CreatedDate Desc LIMIT 10000]; if(CasList.size()>count) { for(Integer i=0; i<count; i++) CasList_Next.add(CasList[i]); shownext = true; } else CasList_Next = CasList; }catch(Exception e){system.debug('Exception :'+e);} } Public Integer GetCasList_Size() { return CasList.size(); } Public List<Case> GetCase() { return CasList_Next; } Public void Next() { try { showprev = true; CasList_Next.clear(); Integer limit1 = 0; if(next+count < CasList.size()) limit1 = next+count; else { limit1 = CasList.size(); shownext = false; } for(Integer i=next; i<limit1; i++) CasList_Next.add(CasList[i]); Next+=count; }catch(Exception e){system.debug('Exception :'+e);} } Public void Prev() { try { shownext = true; CasList_Next.clear(); Integer limit1 = 0; if(next-(count+count) > 0) limit1 = next-count; else { limit1 = next-count; showprev = false; } for(Integer i=next-(count+count); i<limit1; i++) CasList_Next.add(CasList[i]); Next-=count; }catch(Exception e){system.debug('Exception :'+e);} } Public boolean getshownext(){return shownext;} Public boolean getshowprev(){return showprev;} }


 But my Next and Previous Command Links are not displaying despite there being more than 20 records. And it says there are 0 records.



What am I doing wrong?




amar joshiamar joshi

Hi Mattybme,


here i m guessing but it may be it true 


in your  pagination example only custome controller "Paging" is used so it can call its  "Next" and "Privous" Metho.


now as per your code you are using standard controller as well as custome controller 


now in standard List controller there are by default "next" and "Privous" method are there check this Link

so the system confused which method have to call from standard list controller by default method "Next"and "Privous"

or from extension "CaseListController" Public void Next() an Public void Privous()


i think u just change the name of next and privous method.



Thanks & Regards,

Amar Joshi



I am using this extension to my standard controller in my production org:



public with sharing class CaseListController { public ApexPages.StandardSetController setCon {get;set;} public Boolean hasNext {get; private set;} public Boolean hasPrevious {get; private set;} public CaseListController(ApexPages.StandardSetController setCon) { this.setCon = setCon; this.setCon = new ApexPages.StandardSetController(Database.getQueryLocator([select Id, CaseNumber, Subject, CreatedById, Priority, Status, Contact.Name, Account.Name, CreatedDate From Case Order By CreatedDate Desc LIMIT 10000])); this.setCon.setPageSize(25); setNextPrevious(); } public List<Case> getCases() { return (List<Case>) setCon.getRecords(); } public PageReference next() { if (hasNext); setNextPrevious(); return null; } public PageReference previous() { if (hasPrevious) setCon.previous(); setNextPrevious(); return null; } private void setNextPrevious() { if (setCon.getHasNext()) { hasNext = true; } else { hasNext = false; } if (setCon.getHasPrevious()) { hasPrevious = true; } else { hasPrevious = false; } } }

 with this pagination on the VF page:



<apex:panelGrid columns="2" style="font-weight: bold;"> <apex:commandLink action="{!previous}" rendered="{!hasPrevious}"><font color="blue">Previous</font></apex:commandLink> <apex:commandLink action="{!next}" rendered="{!hasNext}"><font color="blue">Next</font></apex:commandLink> </apex:panelGrid>

 What I am trying to do is build into the controller a way to display the number of records in the list. This List is Cases.