+ Start a Discussion
병훈 송병훈 송 

How to development pagination in custom controller

My Visualforce Page Code is
<apex:page standardController="Campaign" recordSetVar="contacts" extensions="Campaign1">
    <apex:form >
    <apex:pageBlock title="Campaign Search">
            <h2>Name : </h2>
            <apex:inputText label="SearchName" value="{!searchName}"/>
            <apex:commandButton value="Search" action="{!searchbox}"> </apex:commandButton>
    <apex:pageBlock title="Campaign Detail">
        <apex:pageBlock title="Contacts List" id="contacts_list">
            <apex:pageBlockTable value="{! campaigns}" var="ct">
                <apex:column value="{! ct.Name }"/>
                <apex:column value="{! ct.Type }"/>
<table style="width: 100%"><tr>
       Page: <apex:outputText value=" {!PageNumber} of {! CEILING(ResultSize / PageSize) }"/>
    <td align="center">
<apex:commandLink action="{! Previous }" value="« Previous"
     rendered="{! HasPrevious }"/>
<apex:outputText style="color: #ccc;" value="« Previous"
     rendered="{! NOT(HasPrevious) }"/>
<apex:commandLink action="{! Next }" value="Next »"
     rendered="{! HasNext }"/>
<apex:outputText style="color: #ccc;" value="Next »"
     rendered="{! NOT(HasNext) }"/>
    <td align="right">
        Records per page:
<apex:selectList value="{! PageSize }" size="1" >
    <apex:selectOption itemValue="5" itemLabel="5"/>
    <apex:selectOption itemValue="20" itemLabel="20"/>
    <apex:actionSupport event="onchange" reRender="contacts_list"/>

and My Custom Controller Code is
public class Campaign1 {

    public Campaign1(ApexPages.StandardSetController controller) {


 public string searchName {get;set;}
 public list < Campaign> campaigns{get;set;}
 public Campaign c {get;set;}
 public Campaign1(apexPages.standardController con) {
 c = (Campaign)con.getRecord();
  campaigns= new list <Campaign> ();
  campaigns= [select ID, Name, StartDate, EndDate, Type from Campaign];
 public void searchbox() {
  campaigns= new list <Campaign> ();
  String name = '%' + searchName + '%';
  campaigns= [select ID, Name, StartDate, EndDate, Type from Campaign where Name Like :name];

I want make the search campaign page in 2 functions
First, Result was pagination
Second, Searched result about keyword.

How to development pagination in custom controller?
Maybe I write Pagination Code on custon controller? but I don't know make it..

Can you help me?
Best Answer chosen by 병훈 송
Hello there, The easiest way s use standard set controller. You can pass the list of items retunred from the search to standard set controller and this will give you already built in methods for NEXT, PREVIOS, FIRST, LAST.

Link for the guide: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_standardsetcontroller.htm