+ Start a Discussion
RamakarryRamakarry 

wraper class with standardsetcontroller

Hai Friends !
Im trying to display records from Leads and Contact in a wrapped pageblock table using standard set controller.
Its confusing how to call records from multiple objects using standard set controller methods.
Can any body correct me?

public class myclass{
public ApexPages.StandardSetController lee{get;set;}  
public ApexPages.StandardSetController con{get;set;}

public List<LeadWrapperCls> records{get;set;}
Public Integer noOfRecords{get; set;}
Public Integer size{get;set;}

public myclass()
        {  
      records = new List<LeadWrapperCls>();
      lee = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, LastName, MobilePhone,Email FROM Lead]));    
      con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, LastName, MobilePhone,Email FROM Contact]));  
      
      lee.setPageNumber(1);     
      lee.setPageSize(5);
      con.setPageSize(5);
      oppt.setPageSize(5);
      noOfRecords = lee.getResultSize() + con.getResultSize();
      getrecords();
      }
  public List<LeadWrapperCls> getrecords()
         {
       
        records = new List<LeadWrapperCls>();  
                for(Lead category : (List<Lead>)lee.getRecords())
                    {
                   records.add(new LeadWrapperCls(category));
                    system.debug('wrapper lead list' +records );                 
                    }                     
         
                  for(Contact category : (List<Contact>)con.getRecords())
                    {
                   records.add(new LeadWrapperCls(category));
                    system.debug('wrapper contact list' +records );
                  //  leadcollect  = new list<lead>();
                    }
                   return records ;
            }
            
            public Boolean hasNext {
        get {
            return lee.getHasNext();
        }
        set;
    }
    public Boolean hasPrevious {
        get {
            return lee.getHasPrevious();
        }
        set;
    }
 
    public Integer pageNumber {
        get {
            return lee.getPageNumber();
        }
        set;
    }
 
    public void first() {
        lee.first();
    }
 
    public void last() {
        lee.last();
    }
 
    public void previous() {
        lee.previous();
    }
 
    public void next() {
        lee.next();
    }   
public class LeadWrapperCls
   {
     public Boolean isSelected {get;set;}
     public Id  id{get;set;}
     public string name{get;set;}
     public string opp{get;set;}
     public String email{set;get;}
     public String phone{set;get;}
     public String type{set;get;}   
     public LeadWrapperCls(Lead llead){
     this.id = llead.Id;  
     this.name=llead.LastName;
     this.email=llead.Email;
     this.phone=llead.MobilePhone;     
      isSelected=false;
      type = 'Lead';
        }
        public LeadWrapperCls(Contact cCon){
        this.id = cCon.Id;  
     this.name=cCon.LastName;
     this.email=cCon.Email;
     this.phone=cCon.MobilePhone;     
      isSelected=false;
      type = 'Contact';
        }
        public LeadWrapperCls(Opportunity opp){
        this.id = opp.Id;  
              
      isSelected=false;
      type = 'Opportunity';
        }
    }
}
===========================================================
<apex:page controller="myclass" >
<apex:form id="fm">
  <apex:pageBlock rendered="{!b}">
   <apex:pageBlockButtons location="top">
      <apex:commandButton action="{!process}" value="Select" reRender="pb,fm"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection columns="1">
      
 <apex:pageblocktable value="{!records }" var="wrapper" id="pb" >
                <apex:column width="25px">                        
                    <apex:inputCheckbox value="{!wrapper.isSelected}"/>
                </apex:column>
                <apex:column value="{!wrapper.type}"/>
                <apex:column value="{!wrapper.id}"/>
                <apex:column value="{!wrapper.name}"/>
                <apex:column value="{!wrapper.email}"/>
                <apex:column value="{!wrapper.phone}"/>
   </apex:pageblocktable>
   <apex:panelGrid columns="7">
                <apex:commandButton status="fetchStatus" reRender="pb" value="first" action="{!first}" disabled="{!!hasPrevious}" title="First Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="previous" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Next" action="{!next}" disabled="{!!hasNext}" title="Next Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Last" action="{!last}" disabled="{!!hasNext}" title="Last Page"/>
            </apex:panelGrid>
            </apex:pageBlockSection>
   </apex:pageBlock>
   </apex:form>
</apex:page>
Amit Chaudhary 8Amit Chaudhary 8
JethaJetha
Hi Rama, 

I have done few changes in your code, otherwise your code looking great to me.
 
public class myclass
{
	public ApexPages.StandardSetController lee{get;set;}  
	public ApexPages.StandardSetController con{get;set;}

	public List<LeadWrapperCls> records{get;set;}
	Public Integer noOfRecords{get; set;}
	Public Integer size{get;set;}

	public myclass()
	{  
		records = new List<LeadWrapperCls>();
		lee = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, LastName, MobilePhone,Email FROM Lead]));    
		con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, LastName, MobilePhone,Email FROM Contact]));  
	  
		lee.setPageNumber(1);     
		lee.setPageSize(5);
		con.setPageSize(5);
		noOfRecords = lee.getResultSize() + con.getResultSize();
		getrecords();
	}
  
	public List<LeadWrapperCls> getrecords()
	{
		records = new List<LeadWrapperCls>();  
		for(Lead category : (List<Lead>)lee.getRecords())
		{
			records.add(new LeadWrapperCls(category));
			system.debug('wrapper lead list' +records );                 
		}                     
 
		for(Contact category : (List<Contact>)con.getRecords())
		{
			records.add(new LeadWrapperCls(category));
			system.debug('wrapper contact list' +records );
		}
		return records ;
	}
	
	public Boolean hasNext 
	{
		get{
		return lee.getHasNext();
		}
		set;
	}
    
	public Boolean hasPrevious 
	{
        get{
		return lee.getHasPrevious();
        }
        set;
    }
 
    public Integer pageNumber 
	{
        get {
            return lee.getPageNumber();
        }
        set;
    }
 
    public void first() 
	{
        lee.first();
    }
 
    public void last() 
	{
        lee.last();
    }
 
    public void previous() 
	{
        lee.previous();
    }
 
    public void next() 
	{
        lee.next();
    }   

	public class LeadWrapperCls
	{
		public Boolean isSelected {get;set;}
		public Id  id{get;set;}
		public string name{get;set;}
		public string opp{get;set;}
		public String email{set;get;}
		public String phone{set;get;}
		public String type{set;get;}   
		
		public LeadWrapperCls(Lead llead)
		{
			this.id = llead.Id;  
			this.name=llead.LastName;
			this.email=llead.Email;
			this.phone=llead.MobilePhone;     
			isSelected=false;
			type = 'Lead';
		}
       
		public LeadWrapperCls(Contact cCon)
		{
			this.id = cCon.Id;  
			this.name=cCon.LastName;
			this.email=cCon.Email;
			this.phone=cCon.MobilePhone;     
			isSelected=false;
			type = 'Contact';
		}
	}
}

Your Page :
<apex:page controller="myclass" >
	<apex:form id="fm">
		<apex:pageBlock >
		<	apex:pageBlockButtons location="top">
				<apex:commandButton value="Select" reRender="pb,fm"/>
			</apex:pageBlockButtons>
			<apex:pageBlockSection columns="1">     
				<apex:pageblocktable value="{!records }" var="wrapper" id="pb" >
					<apex:column width="25px">                        
						<apex:inputCheckbox value="{!wrapper.isSelected}"/>
					</apex:column>
					<apex:column value="{!wrapper.type}"/>
					<apex:column value="{!wrapper.id}"/>
					<apex:column value="{!wrapper.name}"/>
					<apex:column value="{!wrapper.email}"/>
					<apex:column value="{!wrapper.phone}"/>
				</apex:pageblocktable>
				<apex:panelGrid columns="7">
					<apex:commandButton status="fetchStatus" reRender="pb" value="first" action="{!first}" disabled="{!!hasPrevious}" title="First Page"/>
					<apex:commandButton status="fetchStatus" reRender="pb" value="previous" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page"/>
					<apex:commandButton status="fetchStatus" reRender="pb" value="Next" action="{!next}" disabled="{!!hasNext}" title="Next Page"/>
					<apex:commandButton status="fetchStatus" reRender="pb" value="Last" action="{!last}" disabled="{!!hasNext}" title="Last Page"/>
				</apex:panelGrid>
			</apex:pageBlockSection>
	   </apex:pageBlock>
   </apex:form>
</apex:page>

Please don't forget to mark it as best answer, if it resolve your isssue...
RamakarryRamakarry
but here no contacts are calling from pagination methods...and also the check box state for mulriple record selecttion in your page is not maintaining..can you plz  check the code properly?