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
Uttpal chandraUttpal chandra 

How to display record using next button?

Hi all,
I have dispaly 10 record in Pop Up uisng rows=10 in apex:pageBlockTable.

So I want to create a Custom "Next" button in Pop Up which can display the remaining record in Pop up.

Thanks in advance 
Best Answer chosen by Uttpal chandra
Khan AnasKhan Anas (Salesforce Developers) 
Hi Uttpal,

Greetings to you!

You need to use pagination to work around on this. You have to create custom functionality to implement the 10 records per page. You have to create a first, next option so that you can set 10 records per page.

Below is the sample code for pagination which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

<apex:page controller="SoqlPaginationOffsetController">
    <apex:form >
    	<apex:pageBlock id="pb" title="Contacts">
            <apex:pageBlockTable value="{!Contacts}" var="c" id="pt">
            	<apex:column value="{!c.Name}" />
                <apex:column value="{!c.Phone}" />
            <apex:commandButton value="First" action="{!fstbtn}" disabled="{!prv}" reRender="pt,pb" />
            <apex:commandButton value="Previous" action="{!prvbtn}" disabled="{!prv}" reRender="pt,pb" />
            <apex:commandButton value="Next" action="{!nextbtn}" disabled="{!nxt}" reRender="pt,pb" />
            <apex:commandButton value="End" action="{!endbtn}" disabled="{!nxt}" reRender="pt,pb" />

public class SoqlPaginationOffsetController {
    public List<Contact> lstContact;
    public Integer countTotalRecords{get;set;}
    public Integer offSetSize = 0;
	public Integer QueryLimit = 10;
    public SoqlPaginationOffsetController(){
        lstContact = new List<Contact>();
        countTotalRecords = [SELECT count() FROM Contact];
    public List<Contact> getContacts(){
        lstContact = [SELECT Id, Name, Phone FROM Contact ORDER BY Name LIMIT :QueryLimit OFFSET :offSetSize];
        return lstContact;
    public boolean getprv(){
        if(offSetSize > 0)
        	return false;
        	return true;
    public boolean getnxt(){
        if(offSetSize + queryLimit < CountTotalRecords)
        	return false;
        	return true;
    public PageReference nextbtn(){
    	offSetSize += queryLimit ;
    	return null;
    public PageReference prvbtn(){
        offSetSize -= queryLimit ;
    	return null;
    public PageReference fstbtn(){
        offSetSize = 0;
    	return null;
    public PageReference endbtn(){
        offSetSize = countTotalRecords - math.mod(countTotalRecords,queryLimit);
    	return null;

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas