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
niharnihar 

wrapper class and pagination for lead and contact records in salesforce

hi all,
Apex class and visualforce page for
wrapper class and pagination for lead and contact records in salesforce. can anyone help mee i am new to the salesforce coding............
Thanking you all in advance....................
Vamsi_ChinnamVamsi_Chinnam
Hi Nihar,
You need to know the following concepts to understand the code snippet:
1) Collections
2) For loops
3) Wrapper Class

Please find the below class and VF page for Lead and Contactwrapper for your reference
Apex Class:
public class ContactLeadWrapper{
    //Declaring variables
    public list<lead> leadList{get;set;}
    public list<contact> contactList{get;set;}
    
    public list<conleadWrapper> conleadWrapperList{get;set;}
    
    //Constructor
    public ContactLeadWrapper(){
        conleadWrapperList = new list<conleadWrapper>();
        leadList = new list<lead>();
        contactList = new list<contact>();
        contactList = [select id,name from contact limit 5];
        leadList = [select id,name from lead limit 5];
        
        for(integer i=0; i<5; i++){
            conleadWrapper wrapRec = new conleadWrapper(leadList[i],contactList[i]);
            conleadWrapperList.add(wrapRec);
        }
    }
    
    //Wrapper class to hold the lead and contact record
    public class conleadWrapper{
        public lead l{get;set;}
        public contact c{get;set;}
        
        public conleadWrapper(lead l, contact c){
            this.l = l;
            this.c = c;                     
        }
    }
}

Visualforce Page:
<apex:page controller="ContactLeadWrapper" sidebar="false">
    <apex:pageblock title="Displaying Contact - Leads">
        <apex:pageblockTable value="{!conleadWrapperList}" var="wrap">
            <apex:column value="{!wrap.l.Name}" headervalue="Lead Name" />
            <apex:column value="{!wrap.c.Name}" headervalue="Contact Name"/>        
        </apex:pageblockTable>
    </apex:pageblock>
</apex:page>

Hope this helps.
Please mark this as the solution if it helped.
Vamsi_ChinnamVamsi_Chinnam
Also, please find the below link for understanding the wrapper class concept:
http://www.sfdcpoint.com/salesforce/wrapper-class-in-apex/
niharnihar
Hi Vamsi_Chinnam,
Thank you for yor code i have gone through your code actually my requirment is to display leads  records and contact records by using wapper class and pagination. 
Example :
 
User-added image