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
adreameradreamer 

StandardSetController strange behaviour

Hi All,

 

I am experiencing a strange behaviour with a StandardSetController where calls to its methods getRecords() and getResultSize() are inconsistent. Moreover, this is a function of the StandardSetController page size.

 

More in detail now.

 

I have a Visualforce page with a custom controller. The page displays a table of items that are associated with a custom anonymous class defined in the controller.

 

Internally the controller uses a StandardSetController to manage a list of records from which I derive some of the information displayed in the page table.

 

From the UI pespective it is possible to change the page size i.e. how many records the table displays, and navigate through the results in the StandardSetController record set. Internally I use the StandardSetController methods setPageSize(), previous(), etc.

 

When the page size is set to 10, the query used to instantiate the StandardSetController gives 4 records. The StandardSetController

methods in turn give:

- getResultSize() --> 4 records

- getRecords() --> 3 records, so is missing one !

 

However, if the page size changes to 25 or something above, the StandardSetController methods give:

- getResultSize() --> 4 records

- getRecords() --> 4 records, so it is consistent

 

Has somebody seen this type of behaviour ?. 

 

Thanks very much in advance.

Fernando


Bhawani SharmaBhawani Sharma

can you please post your code here?

adreameradreamer

Hi,

 

Thank you for replying.

 

Rather than put you thorugh having to go thorugh a lot of code, here is the part that is causing the problem.

 

private void loadTable(ApexPages.StandardSetController stdSetCont)
    {
       
        this.table.clear();

        try{
            if(this.currentPage==null)
                this.currentPage = 1;
            if(this.pageSize==null || this.pageSize==0)
                this.pageSize=10;
       
            stdSetCont.setPageSize(this.pageSize);
            this.noOfPages = stdSetCont.getResultSize() / stdSetCont.getPageSize();
            if ((this.noOfPages *  stdSetCont.getPageSize()) < stdSetCont.getResultSize())
                 this.noOfPages = this.noOfPages + 1;
            this.lowerEndPage = 1 + ((stdSetCont.getPageNumber() - 1) * this.pageSize);
            this.upperEndPage = this.lowerEndPage + this.pageSize - 1;
            this.noOfItems = stdSetCont.getResultSize();
            
            // set the current page
            this.currentPage = stdSetCont.getPageNumber();
           
            if (this.upperEndPage > this.noOfItems)
                this.upperEndPage = this.noOfItems;     
            this.objects = stdSetCont.getRecords();
            System.debug(this.objects);

 

   for(SObject sObj:this.objects)

   {

// here i retrieve the data of the object in the standard set controller and use it to populate an instance of an anonynous class

           }

     }

     catch(Exception ex)

    {

// handle exception

    }

}

 

The facts:

1. The standard set controller is initialized with a query locator, and the size of the query result gives back 4 records, which is what I expect.

2. In the code above  this.noOfItems is 4 which is correct.

3. In the code above this.objects is a list of SObjects and its size is 3 when the pageSize = 10. This is inconsistent with being  this.noOfItems 4.

4. When the pageSize =25 or any other value (I only have values 25, 50, etc) the same code gives this.noOfItems = 4 and the size of the list of SObjects this.objects is 4 too.

 

Can you spot something wrong in this ?

 

Thank you very much again.

 

Regards,

Fernando