Wrapper Class
Wrapper Class –
public
with sharing class MultiDataDisplayCls {
public List<Employee__c>
lstE{get;set;}
public List<Account> lstA{get;set;}
public List<wrapInner> lstWI{get;set;}
public MultiDataDisplayCls(){
lstE = new List<Employee__c>();
lstA = new List<Account>();
lstE =
[select id,name,Employee_Name__c,employee_city__c from Employee__c limit
3];
lstA =
[select id,name,phone from Account limit 3];
lstWI = new List<wrapInner>();
for(Integer
i=0;i<lstE.size();i++){
wrapInner objWI = new wrapInner();
objWI.objE = lstE[i];
objWI.objA = lstA[i];
lstWI.add(objWI);
}
}
public class wrapInner{ // step1
public Employee__c
objE{get;set;} // setp2
public Account objA{get;set;}
}
}
<apex:page
showHeader="false" controller="MultiDataDisplayCls">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable
value="{!lstWI}" var="w">
<apex:column
headerValue="Employee ID" value="{!w.objE.Name}"/>
<apex:column
headerValue="Account Name" value="{!w.objA.Name}"/>
<apex:column
headerValue="Employee Name"
value="{!w.objE.Employee_Name__c}"/>
<apex:column
headerValue="Account Phone" value="{!w.objA.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
|
wrap records with a check box
- <apex:page controller="EmpDeleteCls">
- <apex:form >
- <!-- <c:companyLogo /> -->
- <apex:pagemessages ></apex:pagemessages>
- <apex:pageBlock >
- <apex:pageBlockTable value="{!lstWI}" var="w">
- <apex:column headerValue="Action">
- <apex:inputcheckbox value="{!w.ischecked}"/>
- </apex:column>
- <apex:column headerValue="Employee ID" value="{!w.objE.Name}"/>
- <apex:column headerValue="Employee Name" value="{!w.objE.Employee_Name__c}"/>
- </apex:pageBlockTable>
- <apex:commandButton value="Delete" action="{!doDelete}"/>
- </apex:pageBlock>
- <!-- <c:companyLogo /> -->
- </apex:form>
- </apex:page>
- public with sharing class EmpDeleteCls {
- public List<Employee__c> lstEToDelete = new List<Employee__c>();
- public Integer selCount =0;
- public PageReference doDelete() {
- try{
- for(wrapEmployee objWE : lstWI){
- if(objWE.ischecked == true){
- selCount++;
- lstEToDelete.add(objWE.objE);
- }
- }
- if(selCount == 0){
- // http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_message.htm
- ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO, 'No Records Selected to Delete....');
- apexpages.addMessage(myMsg);
- return null;
- }
- if(lstEToDelete.size()>0)
- delete lstEToDelete;
- return (new pagereference('/apex/wrapper2').setredirect(true));
- }
- catch(exception e){
- return null;
- }
- }
- public List<Employee__c> lstE{get;set;}
- public List<wrapEmployee> lstWI{get;set;}
- public EmpDeleteCls(){
- lstE = new List<Employee__c>();
- lstE = [select id,name,Employee_Name__c from Employee__c];
- lstWI = new List<wrapEmployee>();
- for(Integer i=0;i<lstE.size();i++){
- wrapEmployee objWE = new wrapEmployee();
- objWE.ischecked = false;
- objWE.objE = lstE[i];
- lstWI.add(objWE);
- }
- }
- public class wrapEmployee{
- public Employee__c objE{get;set;}
- public boolean ischecked{get;set;}
- }
- }
Comments
Post a Comment