I stumbled upon an issue in the article search page today and not able to reason it. Below is the sample controller for querying knowledgearticle which SFDC has provided in the knowledge aricle guide. If you look at the constructor there is a query that fetches all the published articles based on the language, so my question is would the page work properly if my org has more than 50k published articles? i was puzzled because this code is straight from the developer guide and i am hoping that SFDC wouldn't give sample codes which are not bulk efficient. So Incase any of you had faced the issue before pls let me know on how you would tweak the code to support more than 50k records?

public with sharing class vfListPaginationController {
//Page Size
private Static Final Integer PAGE_NUMBER = 10;
public vfListPaginationController() {
// What happens below when the article records > 50k ???    
String qryString = 'SELECT Id, title, UrlName, LastPublishedDate,LastModifiedById FROM
    KnowledgeArticleVersion WHERE (PublishStatus = \'online\' and Language = \'en_US\')';
    List<KnowledgeArticleVersion> articleList= Database.query(qryString);

maxSize = articleList.size() ;
//Keeps track of current page & max size of article list
Integer currentPage = 1;
Integer maxSize = 1;
// Returns whether we need to see previous button or not
public boolean getPrevRequired() {
return currentPage > 1;
// Returns whether we need to see next button or not
public boolean getNextRequired() {
return currentPage * PAGE_NUMBER < maxSize;
//Returns current page number
public Decimal getCurrentPageNumber() {
return this.currentPage;
//action for next click
public PageReference next() {
if(maxSize > this.currentPage * PAGE_NUMBER) {
this.currentPage = this.currentPage + 1;
return null;
//action for previous click
public PageReference previous() {
if(this.currentPage > 1)
this.currentPage = this.currentPage - 1;
return null;

2 Answers 2


One way to do it would be to use the @ReadOnly attribute on the Visualforce page. This allows you to query up to 1 million rows.

The problem with using ReadOnly is that you can't do any DML in the same context. If you do, you get a System.LimitException: Too many DML statements. You can separate it though. Have one page and controller that creates the lists, then have links from there to another page that you go to for DML.

  • thanks daniel, this is good and i like it. But just a question, what happens when there is a DML update on the page, does it show an error or just swallow it? Commented Dec 11, 2012 at 8:22
  • @Anil I've updated my answer. Commented Dec 11, 2012 at 15:37

I suspect the developer guide was just aimed at showing some concept, not really focused on best practices for pagination. Do you have a link? I can't find anything similar...

Do you really really need a homemade pagination solution? I suspect this will be a killer on performance, really trying to query for all articles? Daniel's readonly idea might help...

Can you consider using a StandardSetController? You'll even get "hasNext" / "hasPrevious" methods similar to what you have now but it will perform much better. Here's a sample together with VF code for the actions: http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_controller_sosc_pagination.htm

  • I didn't say my idea was the best, only that it would be one way! I agree that using something like StandardSetController would be a better approach. Commented Dec 10, 2012 at 23:51
  • salesforce.com/docs/developer/knowledge_devpre/index.htm, this is where i got it. Yes, as you rightly said using standard set controllers came first in mind but if articles or knowledge objects are not supported in set controller(my bad, i forgot to mention that in my post) so using set controllers is ruled out. So without set controller i guess we have no option but to implement custom pagination. Commented Dec 11, 2012 at 8:20
  • Then I'm afraid it's LIMIT 50000, @readonly, dividing the data into Categories or not displaying such beast at all... Can you carry on with the examples, this thing looks like some kind of learning exercises and next one (salesforce.com/us/developer/docs/knowledge_dev/… ) shows a filter (but because it's SOSL yoou'll get max 200 rows). Simply experiment with final example code?
    – eyescream
    Commented Dec 11, 2012 at 9:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .