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 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;



Cory CowgillCory Cowgill

You can use a StandardSetController to create pagination functionality in Visualforce Pages.


StandardSetController lets you do things like set the number of recrods in a page, prev/next methods, and other functionalilty specifically needed for paginations.


You can use a standard apex controller class, and inside that class have your STandardSetController which does pagination.


public with sharing class OpptyExtension


      public Opportunity oppty {get;set;}

      public StandardSetController paginationController {get;set;}

public OpptyExtnesion(ApexPages.standardController std)


     oppty = std.getRecord();

     paginationController = new StandardSetController([Select Id, Name from Deal__c where Opportunity__c =: oppty.Id];


public void next()




public void prev()








Then in your VF page you bind a DataTable to the results Sets.