ads

Wednesday 12 April 2017

Wrapper Class: Showing Records in Same Column

In below example i have shown you how we can collect records from different Object in a single
List and shown them in Visualforce page.


We will be user Case and Lead Standard Object to perform this Task ,First i will show you
how we can collect records belongs to different Object in single list and show those records in Same column.


Wrapper Class:-


global class wrapDelete {        
    public wrapDelete (){}
    
    Global class wrapDeleteInner{        
        global Case CaseObj{get;set;}
        global Lead LeadObj{get;set;}
        
        global wrapDeleteInner(){}
        
        }
        
        global List<wrapDeleteInner> getDeleteList(){            
            List<wrapDeleteInner> wrap = new List<wrapDeleteInner>();
            
            for (Lead l:[Select id,name from Lead limit 5]){
                wrapDeleteInner wr = new wrapDeleteInner();
                wr.LeadObj = l;
                wrap.add(wr);                               
            } 
            
            for (Case C:[Select id,CaseNumber from Case limit 5]){
                wrapDeleteInner wr = new wrapDeleteInner();
                wr.CaseObj = C;
                wrap.add(wr);                               
            }            
            return wrap;                                
        }        
    
}

Visualforce Page:-


<apex:page Controller="wrapDelete">       
     <apex:dataTable value="{!DeleteList}" var="item">
          <apex:column headerValue="All Records(Lead and Case)">            
          <apex:outputField value="{!item.LeadObj.name}" />         
             <apex:outputField value="{!item.CaseObj.CaseNumber}" />
          </apex:column>
        </apex:dataTable>
</apex:page>

Output :-


No comments:

Post a Comment