I have custom related lists in a Visualforce component where each of them needs a pagination method. I found many solutions for pagination, but pagination when it is about one object. But what about a single pagination class or pagination methods for more than one object?. Say, I need a pagination for my custom related list A (Object A) and my custom related list B (Object B).
I have the following apex por pagination:
public void fetch()
{
String optyquery = 'SELECT Id, Name FROM Opportunity';
optyquery += ' LIMIT ' + blockSize + ' OFFSET ' + index;
optylist = Database.Query(optyquery);
public void beginning()
{
index = 0;
fetch();
}
public void previous()
{
index = index - blockSize;
fetch();
}
public void next()
{
System.debug('##next!');
index = index + blockSize;
fetch();
}
public void end()
{
Integer mod = math.mod(totalRecs,blockSize);
if (mod != 0) {
index = totalrecs - math.mod(totalRecs,blockSize);
} else {
index = totalrecs - blockSize;
}
fetch();
}
public boolean getprev()
{
if(index == 0)
return true;
else
return false;
}
public boolean getnxt()
{
if((index + blockSize) >= totalRecs)
return true;
else
return false;
}
Is there a way to create one universal pagination class for my two objects so I don't have to write as many pagination classes as objects I have.
Any help would be appreciated.
Thanks Adrian for your tips. You are still dealing with only one object in your examples:
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(query));
and "query" is referring to the object Opportunity:
String query='Select Id,Name, account.name, stagename, ForecastCategoryName FROM Opportunity WHERE Name LIKE \'%' + searchString + '%\' order by Name LIMIT 1000';
if you want this not only for the object Opportunity, but supposing you have two custom related lists both with pagination. Suppose the another object is Contact.
How would you transform your class?.
Another point: I have read in the following link:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_standardsetcontroller.htm
The maximum record limit for StandardSetController is 10,000 records. Instantiating StandardSetController using a query locator returning more than 10,000 records causes a LimitException to be thrown. However, instantiating StandardSetController with a list of more than 10,000 records doesn’t throw an exception, and instead truncates the records to the limit.
If I have more than 10,000 records this will cause a crash. Is that so?
Custom Controller Pagination - easiest way
santanuboral.blogspot.com/2017/03/…