5

i am using a visualforce page which makes a callout to external webservice, get results and displayed in tabular format. i am using apex:pageBlockTable.

Questions:

a) Is that possible to paginate the records from a external webservice?

b) if so, then how the controller would be?

c)i am assuming pagination can be done only with standard and custom objects. is that true?

  • 1
    This is a very broad question which much depends on your page and webservice design. Does the service support pagination ? If not you may want to paginate clientside, doing it server side by caching data in your controller (=viewstate) is likely going to be slow. – Samuel De Rycke Feb 4 '14 at 10:52
  • i am using apex:pageBlockTable to display the results. Asked the webservice provider and it seems service does not support pagination. Do we have any sample code for client side pagination? Usually the pagination can be done with Custom or standard object. how it is possible for webservice results as they are list of records only. How can we issue an select query against that result? Thanks Baskaran – Bforce Feb 4 '14 at 12:04
  • Again, very broad questions. You could opt to insert the data you receive into the database. Is the data parseable to sObject types or json ? There are many clientside pagination options in Javascript frameworks such as jquery. Please try to specify more detail of your architecture and existing code by updating the question. – Samuel De Rycke Feb 4 '14 at 12:43
  • 2
    To add a bit more color. The answers to 'A' and 'C' are yes. Sdry is just trying to urge you to start down the path of a solution first and then ask for help with that solution. There are numerous examples of visualforce controllers performing pagination, both using salesforce objects + Apex and using client side libraries. Really, the best thing to do is to search for some of these solutions, try them, and then come back for help if you need. Good luck! – pchittum Feb 4 '14 at 13:42
  • @Baskaran can you share your vf,apex webservice code once – Sathya Feb 4 '14 at 14:20
3

You can paginate anything you want. Observe:

Controller

public with sharing class pageController {
    public class Item {
        public String A { get; set; }
        public String B { get; set; }
        public String C { get; set; }
    }
    public Item[] items { get; set; }
    public Integer offset { get; set; }
    public pageController() {
       items = new Item[0];
       for(integer index = 0; index < 1000; index++) {
           item tempItem = new Item();
           tempItem.A = "A "+String.valueOf(index);
           tempItem.B = "B "+String.valueOf(index);
           tempItem.C = "C "+String.valueOf(index);
           items.add(tempItem);
       }
       offset = 0;
   }
   public void nextPage() {
       offset = Math.min(offset + 10, items.size() - 10);
   }
   public void previousPage() {
       offset = Math.max(0, offset - 10);
   }
   public void lastPage() {
       offset = items.size() - 10;
   }
   public void firstPage() {
       offset = 0;
   }
}

Page

<apex:page controller="pageController">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockButtons>
                <apex:commandButton action="{!firstPage}" value="First" />
                <apex:commandButton action="{!previousPage}" value="Previous" />
                Starting From: {!offset+1}
                <apex:commandButton action="{!nextPage}" value="Next" />
                <apex:commandButton action="{!lastPage}" value="Last" />
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!items}" var="item" first="{!offset}" rows="10">
                <apex:column headerValue="A" value="{!item.A}" />
                <apex:column headerValue="B" value="{!item.B}" />
                <apex:column headerValue="C" value="{!item.C}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Note that this method only supports 1000 items on a normal page (Visualforce limits), but you could make the entire application client-side driven, potentially loading millions of rows in JavaScript and paging through them using jQuery pagination tables or writing your own JavaScript, etc.

See here that the data obviously doesn't exist in the database at all; it was rendered on the fly.

| improve this answer | |
  • Hi sfdcfox. Now i have Used jQuery datatable for pagination and got this issue: Collection size 1,378 exceeds maximum size of 1,000. Any work around please? – Bforce Apr 28 '14 at 20:27
  • If you're using client side pagination, you need to retrieve the data without using Visualforce. Use JavaScript remoting to accomplish your task. I can expand my answer later if you need more details. – sfdcfox Apr 29 '14 at 0:57
  • @sfdcfox hey, would you like to expand your answer as I am facing the same challenge. – the_phantom Jun 30 '15 at 19:22
0

this does not solve the problem, you are creating data on the fly and he is asking to fetch records from DB, I had a lot of pain doing this and the nearest snip to solve the problem is the one in this link and it doesn't solve it as expected.

try doing from DB and for sure you will get: Too many query locator rows: 10001 error

Server side pagination/processing with Datatable js in Salesforce

| improve this answer | |

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.