+ Start a Discussion

displaying the records in same page on click of next

Hi All,

I want to display all the records in single page 

i.e intial when the  Page  load five records have to display and when i click on next button it has load next 5 records with the inital 5 records 
i.e. a total of 10 records 

Can i have any work around for the above requirement.

Using custom controller or javascript


You can do this with a custom controller and a command button.  If you have an idea of the maximum that you will display, you can simply retrieve them all in the constructor and show them to the user.  If there are likely to be a lot of records that may cause a problem in the view state, in which case you'd be better to retrieve them as part of a getter when the user clicks the button, especially if you aren't allowing the user to make any changes.  Here's an example - thre might be the odd typo but hopefully you get the idea:


public class MyController
    public transient List<Account> accs {get; set;}
    public Integer size {get; set;}

    public MyController()

    private void setupAccounts()
       accounts=[select id, Name from Account limit :size];

   public void next()


<apex:page controller="MyController">
  <apex:pageBlock title="Accounts">
      <apex:commandButton action="{!next}" />
    <apex:pageBlockTable value="{!accounts}" var="acc">
      <apex:column value="{!acc.id}"/>
      <apex:column value="{!acc.Name}"/>


Thanks Bob it worked for me.
can i have the same functionality using javascript
Is there way to display the records without querying again using standard set controller