2

How to show a message/convey to the user that there are more than 10000 records when using StandardSetController?

Do I need to fire a separate SOQL just to count the number of rows and use the LIMT clause in the StandardSetController query to limit the rows? Is there a better way?

Also what is the use of the method getCompleteResult() ? I thought I could use this method to see if there are more than 10000 records in the StandardSet but when there are more than 10000 the page simply errors out with the message "Content cannot be displayed: Too many query locator rows: 10001".

2

If I take an org with over 50000 Account records and run this snippet, I don't get any errors and I do get the expected output:

ApexPages.StandardSetController controller = new ApexPages.StandardSetController([
    SELECT Id FROM Account LIMIT 50000
]);

system.debug(controller.getCompleteResult()); // false
system.debug(controller.getResultSize()); // 10000

And I also get the expected output if the LIMIT is at or below 10000.

ApexPages.StandardSetController controller = new ApexPages.StandardSetController([
    SELECT Id FROM Account LIMIT 10000
]);

system.debug(controller.getCompleteResult()); // true
system.debug(controller.getResultSize()); // 10000

I tested these with API Version set all the way down to 10 on my Apex Class and 15 on my Visualforce Page, and did not receive an error. Perhaps you open another query locator somewhere else on your page somewhere.

<apex:page controller="Throwaway">
    <apex:outputText value="{!IF(controller.completeResult, 'complete', 'partial')}" />
</apex:page>

<!--
public with sharing class Throwaway
{
    public ApexPages.StandardSetController controller
    {
        get
        {
            if (controller == null)
                controller = new ApexPages.StandardSetController([
                    SELECT Id FROM Account LIMIT 50000
                ]);
            return controller;
        }
        private set;
    }
}
-->
| improve this answer | |
  • 1
    Thank for looking into this. Looks like getCompleteResult() method is useful only if we are using the actual list of records(like yours in the example) but not the queryLocator. If I use the standardsetcontroller with list of size greater than 10000, it is working fine and the getCompleteResult returns false. But if I use QueryLocator approach, it throws exception thus making getCompleteResult() method useles. Thanks again! Now it is clear to me. – javanoob Sep 6 '16 at 15:15
  • Also if we use the actual list instead of querylocator to make use of the getCompleteResult() method, I am running into view state issues. I thought standardsetcontroller takes care of viewstate issues by keeping only the current page records in memory irrespective of List of records or querylocator approach..Any idea on this? – javanoob Sep 6 '16 at 15:21
  • @javanoob hard to say without seeing your code. If it has to serialize the whole controller though it's hard to see how it would avoid view state issues. QueryLocator or no. Do you really need an <apex:form> tag on your page? Removing it is the most obvious fix if it's unnecessary, as only pages with such tag track viewstate. – Adrian Larson Sep 6 '16 at 15:23
  • 1
    I will post a separate question with the view state issue and example code. Thanks again! – javanoob Sep 6 '16 at 15:27
1

You can do something like

[select count() from account limit 50000] // you can change the object here.

And if it is greater then 10000 then you can just display the message

| improve this answer | |
  • But what about the getCompleteResult method? From the documentation, looks like we should be able to use this method to know if there are more than 10000 records. When does this method actually return true?? – javanoob Sep 6 '16 at 13:09

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.