Wrapper Class Example with multiple delete options

This is the working example of Wrapper Class with lead as example with multiple delete option.
<apex:page controller="wrapperClas">
    <apex:form >
        <apex:pageBlock id="pbLead">
            <apex:pageBlockButtons >
                <apex:commandButton value="Delete" action="{!del}" rerender="pbLead"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!leadList}" var="l" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!l.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!l.lea.firstname}" />
                <apex:column value="{!l.lea.lastname}" />
                <apex:column value="{!l.lea.company}" />
                <apex:column value="{!l.lea.status}" />
                <apex:column >
                <apex:commandLink value="Edit" action="{!edit}">
                <apex:param name="recId" value="{!l.lea.Id}" assignTo="{!recId}" />
                </apex:commandLink>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller
public class wrapperClas {  
    public List<lLead> leadList {get; set;}
    public Id recId {get; set;}
    public Id delData{get;set;}    
    public wrapperClas()
    {
    fetchAllLeads();
    }   
             
    public PageReference edit() {
    PageReference pgLead = Page.leadtask;
    pgLead.getParameters().put('leadId',recId);
    return pgLead;   
    }    
    private void fetchAllLeads()
        {
            leadList = new List<lLead>();
            for(Lead l: [select  firstname,lastname,company,status from Lead]) {             
                leadList.add(new lLead(l));
            
                        }
               }    
    public void del(){
     List<Lead> selectedLeads = new List<Lead>();
        for(lLead lLea: leadList) {
            if(lLea.selected == true) {
                selectedLeads.add(lLea.lea);
                        }
                              }
            delete selectedLeads;
            fetchAllLeads();
                     }
        public class lLead {
        public Lead lea {get; set;}
        public Boolean selected {get; set;}
        public lLead(Lead l) {
            lea = l;
            selected = false;
        }
    }
}

Comments

Popular posts from this blog

Lightning table with multiple checkbox select options and filter table data.

Lightning DataTable Working Example

What to do when ever you are frustrated with Snort's of ua roomate