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
sai tarunsai tarun 

I have a problem with Pagination, it's working properly on standard object but not custom object.... why?????

<apex:page standardController="sale__c" recordSetVar="sales" sidebar="false">
     <apex:form >
        <apex:pageBlock >
           <apex:pageMessages />
           
            <apex:pageBlockButtons >
               <apex:commandButton value="Save" action="{!save}"/>
               <apex:commandButton value="Return" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!sales}" var="s" id="table" rows="10">
                <apex:column headerValue="Account Name">
                  <apex:outputField value="{!s.Name}"/>
                   </apex:column>
                  <apex:column headerValue="External Id">
                 <apex:inputField value="{!s.External_Id__c}"/>
                   </apex:column>
                <apex:column headerValue="DOJ">
                  <apex:inputField value="{!s.DOJ__c}"/>
                </apex:column>
                <apex:column headerValue="Select">
                  <apex:inputField value="{!s.Select_Intrested_Field__c}"/>
                </apex:column>
                <apex:inlineEditSupport />
            </apex:pageBlockTable>
           
           <apex:commandLink action="{!Previous}" value="Previous Page" rendered="{!HasPrevious}"/>&nbsp;
           <apex:commandLink action="{!Next}" value="Next Page" rendered="{!HasNext}"/>&nbsp;
           <apex:commandLink action="{!Last}" value="Last Page" rendered="{!HasNext}"/>&nbsp;
           <apex:commandLink action="{!First}" value="First Page" rendered="{!HasPrevious}"/>
           
         </apex:pageBlock>
      </apex:form>
 </apex:page>

pagination links are not visible in apex page....
what is the mistake here....
Thanks in Advance
 
Best Answer chosen by sai tarun
PawanKumarPawanKumar
Hi Sai,
There is no probelm in your code. You just make sure you have more than 20 sales__c record in your system. then you will see the effect of pagination. You are able to see the pagination in your standard object as standard object has more than 20 records in your pagination.

Root Cause:
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.

// Overrde default size 20 to 2 as below.
If you want to overide the record per page then you will have to use custom controller for Sales__c object as below. Inthe below custom controller, i have set page size =2 so that you can see the effects of pagination.

----------------VF------------------------------------
<apex:page controller="CustomObjectPaginationController">
     <apex:form >
        <apex:pageBlock >
           <apex:pageMessages />
           
            <apex:pageBlockButtons >
               <apex:commandButton value="Save" action="{!setCon.save}"/>
               <apex:commandButton value="Return" action="{!setCon.cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!customObjects}" var="s" id="table" rows="10">
                <apex:column headerValue="Account Name">
                  <apex:outputField value="{!s.Name}"/>
                   </apex:column>
<!--
                  <apex:column headerValue="External Id">
                 <apex:inputField value="{!s.External_Id__c}"/>
                   </apex:column>
                <apex:column headerValue="DOJ">
                  <apex:inputField value="{!s.DOJ__c}"/>
                </apex:column>
                <apex:column headerValue="Select">
                  <apex:inputField value="{!s.Select_Intrested_Field__c}"/>
                </apex:column>
                <apex:inlineEditSupport />
-->
            </apex:pageBlockTable>
           
           <apex:commandLink action="{!setCon.previous}" value="Previous Page" rendered="{!setCon.hasPrevious}"/>&nbsp;
           <apex:commandLink action="{!setCon.next}" value="Next Page" rendered="{!setCon.hasNext}"/>&nbsp;
           <apex:commandLink action="{!setCon.last}" value="Last Page" rendered="{!setCon.hasNext}"/>&nbsp;
           <apex:commandLink action="{!setCon.first}" value="First Page" rendered="{!setCon.hasPrevious}"/>
           
         </apex:pageBlock>
      </apex:form>
 </apex:page>
---------------------------------

Controller
----------------------------------
public class CustomObjectPaginationController{
public Integer size{get;set;}
    public CustomObjectPaginationController(){
        size=2;
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select id,Name from sale__c]));
                setCon.setPageSize(size);  
            }            
            return setCon;
        }
        set;
    }
     
    // Initialize setCon and return a list of record    
    public List<sale__c> getCustomObjects() {
         return (List<sale__c>) setCon.getRecords();
    }
}

---------------------------------------------------------------

All Answers

PawanKumarPawanKumar
Hi Sai,
There is no probelm in your code. You just make sure you have more than 20 sales__c record in your system. then you will see the effect of pagination. You are able to see the pagination in your standard object as standard object has more than 20 records in your pagination.

Root Cause:
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.

// Overrde default size 20 to 2 as below.
If you want to overide the record per page then you will have to use custom controller for Sales__c object as below. Inthe below custom controller, i have set page size =2 so that you can see the effects of pagination.

----------------VF------------------------------------
<apex:page controller="CustomObjectPaginationController">
     <apex:form >
        <apex:pageBlock >
           <apex:pageMessages />
           
            <apex:pageBlockButtons >
               <apex:commandButton value="Save" action="{!setCon.save}"/>
               <apex:commandButton value="Return" action="{!setCon.cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!customObjects}" var="s" id="table" rows="10">
                <apex:column headerValue="Account Name">
                  <apex:outputField value="{!s.Name}"/>
                   </apex:column>
<!--
                  <apex:column headerValue="External Id">
                 <apex:inputField value="{!s.External_Id__c}"/>
                   </apex:column>
                <apex:column headerValue="DOJ">
                  <apex:inputField value="{!s.DOJ__c}"/>
                </apex:column>
                <apex:column headerValue="Select">
                  <apex:inputField value="{!s.Select_Intrested_Field__c}"/>
                </apex:column>
                <apex:inlineEditSupport />
-->
            </apex:pageBlockTable>
           
           <apex:commandLink action="{!setCon.previous}" value="Previous Page" rendered="{!setCon.hasPrevious}"/>&nbsp;
           <apex:commandLink action="{!setCon.next}" value="Next Page" rendered="{!setCon.hasNext}"/>&nbsp;
           <apex:commandLink action="{!setCon.last}" value="Last Page" rendered="{!setCon.hasNext}"/>&nbsp;
           <apex:commandLink action="{!setCon.first}" value="First Page" rendered="{!setCon.hasPrevious}"/>
           
         </apex:pageBlock>
      </apex:form>
 </apex:page>
---------------------------------

Controller
----------------------------------
public class CustomObjectPaginationController{
public Integer size{get;set;}
    public CustomObjectPaginationController(){
        size=2;
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select id,Name from sale__c]));
                setCon.setPageSize(size);  
            }            
            return setCon;
        }
        set;
    }
     
    // Initialize setCon and return a list of record    
    public List<sale__c> getCustomObjects() {
         return (List<sale__c>) setCon.getRecords();
    }
}

---------------------------------------------------------------
This was selected as the best answer
sai tarunsai tarun
Hi PawanKumar, 
Thank you soo much.......