Easy SF Pagination Tool

Sunday, July 22, 2012 by Aslam - The Alexendra
Hi All,
As most of you must know that Salesforce recently introduced "OFFSET" keyword in SOQL. This feature makes implementation of pagination very easy and effective. Now there is no need to query and store all the records in memory. So it is truly a light weight. So here i have implemented one pagination tool here which is made on "Contact" object. If you want to make it for your custom object, then it is very easy to modify code to work with any object.





You can see demo here for this implementation.
http://labsprojects-developer-edition.ap1.force.com/sf_Pagination

Here is the link for download the package.
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000QEP0

Let me know if you think some kind of enhancement in this.

Thanks
Aslam Bari

5 comments:

prathap said...

Just Curious : OFFSET has a limit of 2000 records as per Salesforce.what If I want to paginate over 2000 records ?(Arguably I wont be clicking on next upto 2000 records, but if i have a search box to filter results I can search only upto 2000 records of my say 10000 rows) Do you have an alternative for that?

Aslam - The Alexendra said...

A normal pagination needs upto 200 rows per page, that is fair enough. I will not like to check every 2000 rows in a single view, thats why we introduce pagination because we want to avoid view of too many rows at once.
But yes, with OFFSET we can't show more that 2000 rows per page.

Abdul Vahid said...

Excellent:)

prathap said...

Aslam I am speaking in context of query not in viewstate. SF says that only 2000 rows can be extracted from say
select Id from account offset 2001 would be erroring out saying :

The maximum offset is 2000 rows. Requesting an offset greater than 2000 will result in a NUMBER_OUTSIDE_VALID_RANGE error.
say i have a query that returns 10000 and i have a search layout and want to offset first 2500 as of today thats not possible, thats what i meant 2000 offset limit.

Hope that clarifies
Please correct if I am wrong.

Anonymous said...

Hi,

I used this pagination control and am getting the error of 'Maximum SOQL offset allowed is 2000', i have more than 10000 records to show in the page.

Can you suggest some thing for this.

Post a Comment