Multiple Leads Conversion with Lightning Component

Simple code to convert multiple Leads at a time.

Apex Class 

public class LeadConversionAuraController {
    //1. The @AuraEnabled annotation enables client- and server-side access to an Apex controller method. Providing this annotation makes your methods available to your Lightning components.
    public static list<leadConversionWrapper> getLeadWithCheckbox(){
        //2. Performing query on lead.
        list<Lead> leadObj =[SELECT id,Name,Email,phone,company,status FROM Lead WHERE IsConverted=false];
        list<leadConversionWrapper> leadWrapper= new list<leadConversionWrapper>();
        for(Lead i:leadObj){
            //3. Adding lead in wrapper class.
            leadWrapper.add(new leadConversionWrapper(i)) ; 
        //4. Returning wrapper class.
        return leadWrapper;
    //5. The @AuraEnabled annotation enables client- and server-side access to an Apex controller method. Providing this annotation makes your methods available to your Lightning components.
    //6. This method used to convert lead.
    public static void convertSelectedLead(List<Lead> selectedLead){
        for(lead leadObj: selectedLead){
            Database.LeadConvert lc = new Database.LeadConvert();
            LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            //7. Lead conversion.
            Database.LeadConvertResult lcr = Database.convertLead(lc);
    // 8. Wrapper class to hold lead with checkbox.
    Public class leadConversionWrapper{
        Public Lead leadObj;
        Public Boolean isBoolean;
        public leadConversionWrapper(Lead leadObj){
            this.leadObj = leadObj;
            this.isBoolean = isBoolean;


Lightning Component 

<aura:component controller="LeadConversionAuraController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <!-- 2.handler to call method "doInit" of jsCOntroller on loading of component. -->
    <aura:handler name="init" value="{!this}" action="{!c.leadwithcheckbox}"/>
    <!-- 1.attribute to store return value and show on component. -->
    <aura:attribute name="leadWrapper" type="LeadConversionAuraController.LeadConversionAuraController[]" />
    <br/><div class="slds-grid">
    <div class="slds-col slds-size--6-of-6">
        <center><ui:button class="detilbuton" label="Convert Lead" press="{!c.convertLead}"/></center>
    <div class="slds-p-horizontal--small slds-size--1-of-1 slds-medium-size--1-of-1 slds-large-size--1-of-1">
        <div class="table-responsive">
            <table id="tableI" class="slds-table slds-table--bordered table" >
                <!-- Table header -->
                    <tr class="slds-text-title--caps header">
                        <td width="100"> Select </td>
                        <td> Name </td>
                        <td> Company </td>
                        <td> Email  </td>
                        <td> Phone </td>
                        <td> Status</td>
                <!-- Table body -->
                    <aura:iteration items="{!v.leadWrapper}" var="item">
                                <div class="checkbox">
                                    <ui:inputCheckbox aura:id="checkbox" value="{!item.isBoolean}"/>
    // 1. This is called on loding of component.
    leadwithcheckbox : function(component, event, helper) {
        //2. Calling method "getLeadWithCheckbox" of apex class "LeadConversionAuraController".
        var action =component.get("c.getLeadWithCheckbox");
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                //3.Setting return value of method "getLeadWithCheckbox" of apex class "LeadConversionAuraController" to attribute "leadWrapper".
                component.set("v.leadWrapper", response.getReturnValue());
        //4. $A.enqueueAction adds the server-side action to the queue.
    // 5. This is called by Conver Lead button.
    convertLead : function(component, event, helper){
        // 6. Getting wrapper list.
        var leadWrapper = component.get("v.leadWrapper");
        //7. Calling method "convertSelectedLead" of apex class "LeadConversionAuraController".
        var action = component.get("c.convertSelectedLead");
        // 8. Array decleration.
        var selectedLead = new Array();
        for(var i=0; i < leadWrapper.length; i++){
                // 9. Hold selected lead to convert.
        if(selectedLead.length > 0){
            action.setCallback(this, function(response){
                // 10. Checking status of response.
                var state = response.getState();
                if (state === "SUCCESS") {
                    alert('Lead isconverted sucessfully.');
                    alert('Error occurred while converting lead.');
            alert('Please select any Lead');



<aura:application extends="force:slds">
    <!-- Calling component "MultipleLeadConversion" -->