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
PuranKishorePuranKishore 

Pagination using wrapper class standard Contact

<apex:page controller="wrapperexample_controller" sidebar="false">
    <apex:form >
        <apex:pageBlock id="b">
            <apex:pageBlockTable value="{!listvalues}" var="lv">
                <apex:column value="{!lv.Id}"/>
                <apex:column value="{!lv.Name}"/>
                <apex:column value="{!lv.Email}"/>
                <apex:column value="{!lv.Phone}"/>
            </apex:pageBlockTable>
            
        <apex:commandLink value="NextPage" action="{!Next}" reRender="b"/>
        <apex:commandLink value="PreviousPage" action="{!Previous}" reRender="b"/>
        <apex:commandLink value="FirstPage" action="{!First}" reRender="b"/>
        <apex:commandLink value="LastPage" action="{!Last}" reRender="b"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

 

 

 

public class wrapperexample_controller
{
    public wrapperexample_controller()
    {
        /* for(Contact c:[select Id, Name, Phone, Email from Contact])
        {
            wrapper w = new wrapper();
            w.Id = c.Id;
            w.Name = c.Name;
            w.Phone = c.Phone;
            w.Email = c.Email;
            lst.add(w);
        } */
    }
    public apexpages.standardsetcontroller con
    {
        get
        {
            if(con == Null)
            {
                con = new ApexPages.standardsetcontroller(Database.getQueryLocator([Select Id, Name, Phone, Email from Contact Order By LastName limit 100]));
                con.setpagesize(10);
            }
            return con;
        }
    }
    
    
    public list<Contact> lst = new list<Contact>();
    
   
    public list<Contact> getlistvalues()
    {
         for( Contact ct:(list<Contact>)con.getrecords())
         {
             lst.add(ct);
         }
       
        return lst;
    }
        
    public class wrapper
    {
        public String Id{set;get;}
        public String Name{set;get;}
        public String email{set;get;}
        public String Phone{set;get;}
    }
    public void next()
    {
        con.next();
    }
    public void previous()
    {
        con.previous();
    }
    public void first()
    {
        con.first();
    }
    public void last()
    {
        con.last();
    }
    public Boolean hasNext {
        get {
            return con.getHasNext();
        }
        set;
    }
    public Boolean hasPrevious {
        get {
            return con.getHasPrevious();
        }
        set;
    }
}

Amit Chaudhary 8Amit Chaudhary 8

If you are still looking for solution. Then Please check below blog :-
http://amitsalesforce.blogspot.in/2014/11/pagination-with-wrapper-class-with.html

Thanks,
Amit Chaudhary