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 in custom related list

Hi All,


     Any Idea of how to create pagination in custom related list.Here is my page and class. I need to display 5 oppty records.If there are more than 5 records then i need to show a link  Show More link which goes to next page and displays all records like below.




<apex:page standardController="Contact" extensions="sampleDetailPageCon">
.fewerMore { display: none;}
<apex:form >
 <apex:pageMessages />
 <apex:detail relatedList="false"></apex:detail>
<apex:pageblock id="CustomList" title="Related Opportunities"  >
   <apex:pageBlockTable value="{!oppz}" var="o" rendered="{!NOT(ISNULL(oppz))}">
        <apex:column value="{!o.Name}"/>
        <apex:column value="{!o.Account.Name}"/>
        <apex:column value="{!o.Type}"/>
       <apex:column value="{!o.Amount}"></apex:column>
       <apex:column value="{!o.CloseDate}"/>
   <apex:outputLabel value="No records to display" rendered="{!(ISNULL(oppz))}" styleClass="noRowsHeader"></apex:outputLabel>




public class sampleDetailPageCon {
    private List<Opportunity> oppz;
    private Contact cntact;
    public sampleDetailPageCon(ApexPages.StandardController controller) {
        this.cntact= (Contact)controller.getRecord();
    public List<Opportunity> getOppz()
        Contact con = [Select id, FROM Contact where id =];
        if (con.Account == null)
         return null;
        oppz = [Select id, Name, Account.Name, CloseDate, Amount, Type from Opportunity where =];
        return oppz;




I've had to do this a couple of times in the past.  The mechanism I've used is as follows:


(1) Retrieve all records that will be available in a single query and store in a master list. 

(2) Store the first 'n' records into a list for display, where n=page size

(3) Store the current position in a property (as zero)

(3) Set up boolean properties for previous/next links.  If the current position is zero, don't activate the previous link, if the cutrrent position >= total records - page size don't display the next link

(4) In the page, use the for display list rather than the master list.


When the user clicks one of the links, update the current position and copy a page worth of records from the master list to the display list based on the current position. Then start from point (3) to decide what links to display etc.

Hi Bob,


       Thanks for your reply.Can you please post sample code.





Did you ever get your paging figured out?