How To Create Pagination Within Salesforce

How To Create Pagination Within Salesforce

By admin December 2, 2013
Salesforce Development, Services 3

Another question has been sent to us and we thought it would be good to share these step by step directions with the Salesforce development world. The question was how to do Pagination within Salesforce if I have 100,000 records. Pagination is the process of taking a complete document or a large number of records in this example and breaking that document/large number of records into separate pages for viewing within the Salesforce. For example, let’s say we want to display a list of records that only shows 10 records within each page rather than a huge set within Salesforce. The Salesforce user can click the next tab and go through each new page display the next 10 records. Please follow these step by step directions of how to make this pagination feature within your Salesforce CRM.

4

Step 1 –

Go To Setup → Develop → Pages

Click the “New” Button for creating new pages:

1

Step 2 – In The Label & Name Box Type “pagination”

2

Step 3 – In Visualforce editor paste the following code:



















Step 4 – Paste this controller code in Apex Class editor:

public class Pagination
{
private integer totalRecs = 0;
private integer OffsetSize = 0;
private integer LimitSize= 10;
public Pagination()
{
totalRecs = [select count() from account];
}
public List getacclist()
{
List acc = Database.Query('SELECT Name, website, AnnualRevenue, description, Type FROM account LIMIT :LimitSize OFFSET :OffsetSize');
System.debug('Values are ' + acc);
return acc;
}
public void FirstPage()
{
OffsetSize = 0;
}
public void previous()
{
OffsetSize = OffsetSize – LimitSize;
}public void next()
{
OffsetSize = OffsetSize + LimitSize;
}public void LastPage()
{
OffsetSize = totalrecs – math.mod(totalRecs,LimitSize);
}
public boolean getprev()
{
if(OffsetSize == 0)
return true;
else
return false;
}
public boolean getnxt()
{
if((OffsetSize + LimitSize) > totalRecs)
return true;
else
return false;
}
}

“Save” this code

Step 5 – Open this page in your Salesforce organization to check its working correctly: “https://ap1.salesforce.com/apex/Pagination”.

3

Step 6 – Enjoy! If you have any questions, please feel free to contact us as our expert Salesforce developers would be more than happy to assist you with any of your Salesforce development needs.

Related Posts

Popular post