function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

getCompleteResult on setControllers using a database queryLocator with a LIMIT clause

I have a setController where I'm using a database.queryLocator entering a query string that ends with a LIMIT clause under 10000. 

When I set the LIMIT clause in the query string, the setCon.getCompleteResult() method reports as TRUE - that is all the records were found. The problem is that we have over 10000 records of this object, so I would expect the setController response to be FALSE. 

If I remove the LIMIT clause in the query string, the system returns a too many rows error. 

I don't see any examples on the board, in the documentation, or anywhere else where the getCompleteResult() method on the setController is used in a situation where there are too many records in the database, so I don't see when the getCompleteresult() method would ever return a value of FALSE. If you add a LIMIT clause to the query, getCompleteResult() says I got all the records, which I know isn't true. If I don't, I get the query error. 

// this is supposed to tell the user that the result is incomplete and to apply a filter
public boolean resultComplete {get; set;}

public ApexPages.StandardSetController SetCon {
        get {
            if(SetCon == null) {
                System.debug('SetCon is null; loading');
                String query = getQuery();   //returns query string ending with 'LIMIT 5000'
                SetCon = new ApexPages.StandardSetController(Database.getQueryLocator(query));

            numAvailableLogs = setCon.getResultSize(); // this = 5000
            System.debug('numAvailableLogs is '+numAvailableLogs);

            numPages = (math.mod(numAvailableLogs,pageSize) == 0)? (numAvailableLogs/pageSize) : ((numAvailableLogs/pageSize)+1); 

            resultComplete = setCon.getCompleteResult(); // this returns true (there are more records)
            System.debug('setCon resultComplete is '+resultComplete);

            hasNext = setCon.getHasNext();
            hasPrevious = setCon.getHasPrevious();
            pageNumber = setCon.getPageNumber();
            return SetCon;

Anup JadhavAnup Jadhav
Just to clarify, when you remove the LIMIT clause, you get the debug output for resultComplete as TRUE? or it just throws too many rows error.