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
Developer129Developer129 

StandardSetController setPageSize does not work

Hi,

 

I am having problems working with the StandardSetController class, I have setPageSize to '2' however when I call getRecords() it keeps on giving me all the records. Also getResultSize() is equal to 3

 

Is this a bug or am i doing something wrong

 

Thanx

Pradeep_NavatarPradeep_Navatar

Try the sample code given below to get setpagesize() and getResultsize() :

 

                                                public with sharing class zipMap

                                                {

                                                                public ApexPages.StandardSetController accts

                                                                {

                                                                   get

                                                                   {

                                                                                                accts = new ApexPages.StandardSetController

                                                                                                (

                                                                                                                  Database.getQueryLocator([SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode = '10022'])

 

                                                                                                );

                                                                                                accts.setPageSize(4);

                                                                                    return accts;

                                                                                }

                                                                                set;

                                                                }                                             

                                                                public Integer pages

                                                                {

                                                                   get

                                                                   {

                                                                                 pages = accts.getResultSize()/accts.getPageSize();

                                                                                 system.debug('>>>>>>' + pages);

                                                                                 return pages;

                                                                   }

                                                                   set;

                                                                }

                                                }

 

Hope this helps.

Developer129Developer129

Thank for the reply. Your suggestion worked perfectly, however now I am facing a new issue regarding this pagination. I read in the documentation that we can instantiate the StandardSetController by the following code:

 

List<account> accountList = [SELECT name FROM Account LIMIT 20];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountList);

 

however when I instantiate with this all records are showing on the page even though the page size is set. Also when I create the list manually in the code rather then getting it from the DB i get this error

 

"Modified rows exist in the records collection!"

 

 

 

 

 

 

 

A.B.ax793A.B.ax793

Did any one get the Solution for this:

 

List<account> accountList = [SELECT name FROM Account LIMIT 20];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountList);

 

ERROR:"Modified rows exist in the records collection!"