• WHO WE ARE
  • WHAT WE DO
    • Salesforce
      • Implementations
        • Sales Cloud
        • Service Cloud
        • CPQ
        • Field Service Lightning
        • Field Service for SMEs
      • Developments
        • Salesforce Customization
        • Custom Application Development
        • AppExchange Product Development
      • Migrations
        • Classic to Lightning Migration
        • Other Systems to Salesforce Migration
      • Integrations
    • Data Science
      • BI Solutions
      • AI/ML solutions
      • Agentic AI
  • HOW WE DO
    • Delivery Model
    • Our Works
  • REACH US
    • Contact Us
    • Careers
  • BLOG
    • WHO WE ARE
    • WHAT WE DO
      • Salesforce
        • Implementations
          • Sales Cloud
          • Service Cloud
          • CPQ
          • Field Service Lightning
          • Field Service for SMEs
        • Developments
          • Salesforce Customization
          • Custom Application Development
          • AppExchange Product Development
        • Migrations
          • Classic to Lightning Migration
          • Other Systems to Salesforce Migration
        • Integrations
      • Data Science
        • BI Solutions
        • AI/ML solutions
        • Agentic AI
    • HOW WE DO
      • Delivery Model
      • Our Works
    • REACH US
      • Contact Us
      • Careers
    • BLOG
  • [email protected]
  • (+91) 44-49521562
Merfantz - Salesforce Solutions for SMEs
Merfantz - Salesforce Solutions for SMEs
  • WHO WE ARE
  • WHAT WE DO
    • Salesforce
      • Implementations
        • Sales Cloud
        • Service Cloud
        • CPQ
        • Field Service Lightning
        • Field Service for SMEs
      • Developments
        • Salesforce Customization
        • Custom Application Development
        • AppExchange Product Development
      • Migrations
        • Classic to Lightning Migration
        • Other Systems to Salesforce Migration
      • Integrations
    • Data Science
      • BI Solutions
      • AI/ML solutions
      • Agentic AI
  • HOW WE DO
    • Delivery Model
    • Our Works
  • REACH US
    • Contact Us
    • Careers
  • BLOG

How to Change Pagination View Dynamically Using Visualforce Page in Salesforce

  • August 1, 2017
  • Merfantz Editor
  • Salesforce Developments Tutorial
  • 0

This article is useful whenever you have an issue to split full page content. Pagination concept is a help to avoid this kind of issue. Pagination is nothing but some time the full page has long content so we could not able to view and had a bitterness to see. In that situation, this article is a support to you.

Here we provide an example showing, the full page is divide which is showing how you set page result size and the starting point of the record at the run time.

Try the below code –

Visualforce page –

<apex:page controller=”AccountDetails” showHeader=”false” sidebar=”false”>

<apex:sectionHeader  title=”Pagination Sample”/>

<apex:pageBlock >

<apex:form >

<apex:outputLabel >Starting Record</apex:outputLabel>

<apex:inputText value=”{!counter}” style=”margin-left:100px;”>

<apex:actionSupport event=”OnClick” reRender=”myPanel,myButtons” action=”{!getAccounts}”/>

</apex:inputText>

</apex:form>

<apex:form >

<apex:outputLabel style=”margin-top:10px;”>Records Limit</apex:outputLabel>

<apex:inputText value=”{!list_size}” style=”margin-left:110px;margin-top:10px;”>

<apex:actionSupport event=”onClick” reRender=”myPanel,myButtons” action=”{!getAccounts}”/>

</apex:inputText>

</apex:form>

</apex:pageBlock>

<apex:pageBlock >

<apex:pageBlockButtons location=”top” >

<apex:outputPanel id=”myButtons”>

<apex:form >

<apex:commandButton action=”{!Beginning}” title=”Beginning” value=”<<” disabled=”{!disablePrevious}” reRender=”myPanel,myButtons”/>

<apex:commandButton action=”{!Previous}” title=”Previous” value=”<” disabled=”{!disablePrevious}” reRender=”myPanel,myButtons”/>

<apex:commandButton action=”{!Next}” title=”Next” value=”>” disabled=”{!disableNext}” reRender=”myPanel,myButtons”/>

<apex:commandButton action=”{!End}” title=”End” value=”>>” disabled=”{!disableNext}” reRender=”myPanel,myButtons”/>

</apex:form>

</apex:outputPanel>

</apex:pageBlockButtons>

<apex:pageBlockSection columns=”1″>

</apex:pageBlockSection>

<apex:pageBlockSection title=”Result” collapsible=”false”>

<apex:outputPanel id=”myPanel”>

<apex:pageMessages id=”theMessages” /><p style=”color:blue;”>Total List Size: {!total_size}</p><br/>

<apex:pageBlockTable value=”{!accounts}” var=”acc” align=”center”>

<apex:column value=”{!acc.AccountNumber}” />

<apex:column value=”{!acc.Name}” />

<apex:facet name=”footer”>Page # {!pageNumber} of {!totalPages}</apex:facet>

</apex:pageBlockTable>

</apex:outputPanel>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:page>

Apex Class :-

public with sharing class AccountDetails{

public integer counter{set;get;} //keeps track of the offset

public integer list_size{set;get;} //sets the page size or number of rows

public integer total_size; //used to show user the total size of the list

public AccountDetails() {

counter=0; // starting position of a record

list_size=10; // set default size per page

total_size = [select count() from Account]; //set the total size in the constructor

}

public Account[] getAccounts() {

try {

Account[] accounts = [select Id, Name, AccountNumber,Type from Account order by Name limit :list_size offset :counter];

return accounts;

} catch (QueryException e) {

catch (QueryException e) {

ApexPages.addMessages(e);

return null;

}

}

public PageReference Beginning() { //user clicked beginning

counter = 0;

return null;

}

public PageReference Previous() { //user clicked previous button

counter -= list_size;

return null;

}

public PageReference Next() { //user clicked next button

counter += list_size;

return null;

}

public PageReference End() { //user clicked end

counter = total_size – math.mod(total_size, list_size);

return null;

}

public Boolean getDisablePrevious() {

//this will disable the previous and beginning buttons

if (counter>0) return false; else return true;

}

public Boolean getDisableNext() { //this will disable the next and end buttons

if (counter + list_size < total_size)

return false;

else

return true;

}

public Integer getTotal_size() {

return total_size;

}

public Integer getPageNumber() {

return counter/list_size + 1;

}

public Integer getTotalPages() {

if (math.mod(total_size, list_size) > 0) {

return total_size/list_size + 1;

} else {

else {

return (total_size/list_size);

}

}

}

Result :-

Enter number of records you want to show in the each page,

Enter starting position of the record,

We are the ISV Partners and Please reach us for custom development => www.merfantz.com

———————— We hope it will help you —————————

Author Bio

Merfantz Editor
+ Recent Posts
  • August 4, 2023
    How to Setup CRM Analytics for Financial Services Cloud
  • August 2, 2023
    How to Get Started with Salesforce Hyperforce - Merfantz
  • July 28, 2023
    Health Cloud Mastery: Salesforce Trailhead for Effective Healthcare CRM
  • July 26, 2023
    How to integrate Data cloud and Marketing cloud In Salesforce
Tags: Field Service ManagementFieldax
  • Previous Use of rendered, renderAs and reRerender in Salesforce
  • Next Dynamically Remove Table Column Based on Header Name in Salesforce

Leave a Reply

You must be logged in to post a comment.

Merfantz Technologies is a leading Salesforce consulting firm dedicated to helping small and medium enterprises transform their operations and achieve their goals through the use of the Salesforce platform. Contact us today to learn more about our services and how we can help your business thrive.

Discover More

Terms and Conditions
Privacy Policy
Cancellation & Refund Policy

Contact Info

  • No 96, 2nd Floor, Greeta Tech Park, VSI Industrial Estate, Perungudi, Chennai 600 096, Tamil Nadu, INDIA
  • (+91) 44-49521562
  • [email protected]
  • 9:30 IST - 18:30 IST

Latest Posts

Comprehensive Overview of Salesforce Agent-Force Platform
Comprehensive Overview of Salesforce Agent-Force Platform June 12, 2025
Salesforce GraphQL Revolutionizing Data Queries in CRM
Salesforce GraphQL: Revolutionizing Data Queries in CRM June 6, 2025
Unlocking the Power of Dynamic Forms in Salesforce Lightning App Builder
Unlocking the Power of Dynamic Forms in Salesforce Lightning App Builder May 29, 2025

Copyright @2023 Merfantz Technologies, All rights reserved