Need to Create a page to display all the account records existing the instance. It should display 20 records in one page and should have NEXT & PREVIOUS button to navigate to other records.

but it should not fetch more than 20 records in single query.


Your best bet is the create a Visualforce page the calls the controller to fetch the record using JavaScript Remoting. There is also a somewhat new OFFSET keyword which makes pagination a breeze.

  • 3
    Seems like the right architecture, a code sample would make this a great answer.
    – greenstork
    Nov 14 '13 at 16:22
  • I'm sitting on the runway on my phone so rather difficult at the moment. ;) Nov 14 '13 at 20:05

I was actually trying to write something for a coding example, but came across this answer that @sfdcfox came up with. It's actually a really cool trick to use, and I'm actually going to play around with it, as it seems like a pretty simple and elegant way to workaround the limit of 2000 rows for using OFFSET in SOQL.

Looks like exactly what would help for your scenario. I would check this out.

How can I use 'query more' using javascript remoting?


For up to 10k records, you can use the StandardSetController:

<apex:page standardController="Account" recordSetVar="accounts">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!first}" value="First"/>
                <apex:commandButton action="{!previous}" value="Previous"/>
                <apex:commandButton action="{!next}" value="Next"/>
                <apex:commandButton action="{!last}" value="Last"/>
            <apex:pageBlockTable value="{!accounts}" var="account">
                <apex:column value="{!account.name}"/>

If you add a custom controller or extension, you can assign any query up to 10,000 rows for automatic pagination. Take a look at the StandardSetController documentation for further examples.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.