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
Shantanu Mahajan 4Shantanu Mahajan 4 

Pagination for Wrapper Class

Hii all,

I am trying to paginate using Offset, but it is giving me error " System.QueryException: Maximum SOQL offset allowed is 2000"
And I cannot use Standard set Controller becuase it is giving me error  " List controllers are not supported for Attachment "

So how can i do pagination now

 
Alexander TsitsuraAlexander Tsitsura
Hi Shantanu,

When i implemented pagination for wrapper class i use offsedId. I remember each 2000th record id and my soql look as
SELECT Id, ..., FROM Account WHERE Id > :offsetId

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex
 
Shantanu Mahajan 4Shantanu Mahajan 4
Hi Alexander

My Query is like 
 
String queryList = 'select Id, Name,BodyLength ,CreatedDate,Owner.Name from Attachment where BodyLength>=' + sSliderFieldMin + ' AND BodyLength<=' + sSliderFieldMax ;        
            if (attachmentToUser.OwnerId != NULL) {
                queryList += ' AND OwnerId =\'' + attachmentToUser.OwnerId + '\'';
            }
           
            queryList += ' order by ' + sortFullExp + ' Limit ' + list_size+ ' offset ' + counter;

so how can i give offsetId??
Alexander TsitsuraAlexander Tsitsura
Hi Shantanu,

I remember each 2000th record id. When user navigate to next page and current page contains 2000th record, i remember it, and when user click "next page" i add filter in where statement "offsetId > recordId".

for example contact table
1999. Test Contact
2000. Test Contact 2
2001. Test Contact 3

and you want query 10 records start with 2000 to 2010, for it you need remember id of 1999th contact and use this id for drop first 1999 contact. In this scenarion you offset every time should be less 2000. 

Thanks,
Alex