1

I don't understand why the getCompleteResult method returns true. From the documentation, I'm not clear what this method does. Can you help clarify it?

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardSetController_getCompleteResult.htm

//clear all accounts;

  List<Account> accts = new List<Account>();
  for(Integer i = 0; i < 9000; i++)
  {
    accts.add(new Account(name = test + i));
  }

  insert accts
  ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(Database.getQueryLocator([
          SELECT 
            Id, Name
          FROM Account       
          LIMIT 10000
        ]));      
  System.debug('has more? ' + setCon.getCompleteResult());

1 Answer 1

2

The StandardSetController has a limit of 10,000 records. If your query returns more than that, the result will be incomplete. The documentation does exactly what it says:

Indicates whether there are more records in the set than the maximum record limit. If this is false, there are more records than you can process using the list controller. The maximum record limit is 10,000 records.

See also: Content cannot be displayed: Too many query locator rows: 10001

Basically, if you have more records than the controller can handle, the result is false because the set is not complete. If you have an amount within the limit, than the result is true because the set is complete.

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

system.assertEquals(false, controller.getCompleteResult());
system.assertEquals(10000, controller.getResultSize());

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

system.assertEquals(true, controller.getCompleteResult());
system.assertEquals(10000, controller.getResultSize());
2
  • so, in my example i only have 9k accounts. why does it return true? Feb 22, 2017 at 6:23
  • @user because then the controller can handle the complete record set.
    – Adrian Larson
    Feb 22, 2017 at 6:30

You must log in to answer this question.

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