function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Manu Reddy0483Manu Reddy0483 

Number of leads from different states using lightning component ?

Hi

Number of leads from different states using lightning component ?

Thanks

 
Best Answer chosen by Manu Reddy0483
Raj VakatiRaj Vakati
public class LeadStatus {
    @auraenabled
    public static List<StatusWrapper> leadStatus(){
        List<StatusWrapper> wrapper = new List<StatusWrapper>() ; 
        AggregateResult[] Result = [SELECT Count(Id) Total ,
                                    Status statusName FROM Lead   GROUP BY Status];
        for (AggregateResult ar : Result) {
            wrapper.add(new StatusWrapper((String)ar.get('statusName') ,(Integer)ar.get('Total')));
        }
        
        return wrapper ;
        
    }
    
    public class StatusWrapper{
        @auraenabled
        public String status {get;set;}
        @auraenabled
        public Integer count {get;set;}
        public StatusWrapper(String status , Integer count){
            this.status = status ;
            this.count = count ; 
            
        }
        
    }
    
}
 
<aura:component controller="LeadStatus" implements="force:appHostable" >
    
    <aura:attribute name="leads" type="List[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <table border="1" class="table">
        <tr>
            <th>Status&nbsp;&nbsp;</th> 
            <th>Count&nbsp;</th>
        </tr><br/>
        <aura:iteration items="{!v.leads}" var="cust">
            <tr> 
                <td>{!cust.status}</td>
                <td>{!cust.count}</td>       
            </tr>
        </aura:iteration>
    </table>
    
</aura:component>
 
({
    doInit : function(component, event) {
        var action = component.get("c.leadStatus");
        action.setCallback(this, function(a) {
            component.set("v.leads", a.getReturnValue());
        });
        $A.enqueueAction(action);
    }
})

Use the above code

All Answers

Raj VakatiRaj Vakati
Hi Manu, 

Do you want to show the number of leads by the state on the Lead layout? 
If you want you can able to do it with default lead kanban layout from the list views. Please see the image 

User-added image

 
Manu Reddy0483Manu Reddy0483
Thanks for reply Raj
Using Lightning componet I need to display below Formate

User-added image
Raj VakatiRaj Vakati
public class LeadStatus {
    @auraenabled
    public static List<StatusWrapper> leadStatus(){
        List<StatusWrapper> wrapper = new List<StatusWrapper>() ; 
        AggregateResult[] Result = [SELECT Count(Id) Total ,
                                    Status statusName FROM Lead   GROUP BY Status];
        for (AggregateResult ar : Result) {
            wrapper.add(new StatusWrapper((String)ar.get('statusName') ,(Integer)ar.get('Total')));
        }
        
        return wrapper ;
        
    }
    
    public class StatusWrapper{
        @auraenabled
        public String status {get;set;}
        @auraenabled
        public Integer count {get;set;}
        public StatusWrapper(String status , Integer count){
            this.status = status ;
            this.count = count ; 
            
        }
        
    }
    
}
 
<aura:component controller="LeadStatus" implements="force:appHostable" >
    
    <aura:attribute name="leads" type="List[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <table border="1" class="table">
        <tr>
            <th>Status&nbsp;&nbsp;</th> 
            <th>Count&nbsp;</th>
        </tr><br/>
        <aura:iteration items="{!v.leads}" var="cust">
            <tr> 
                <td>{!cust.status}</td>
                <td>{!cust.count}</td>       
            </tr>
        </aura:iteration>
    </table>
    
</aura:component>
 
({
    doInit : function(component, event) {
        var action = component.get("c.leadStatus");
        action.setCallback(this, function(a) {
            component.set("v.leads", a.getReturnValue());
        });
        $A.enqueueAction(action);
    }
})

Use the above code
This was selected as the best answer
Manu Reddy0483Manu Reddy0483
Thanks for Reply
Raj VakatiRaj Vakati
It looks good? Make it solved .!
Manu Reddy0483Manu Reddy0483
Yes, Its Solved Raj V
Manu Reddy0483Manu Reddy0483
When click on State Name, Leads Records will displayed, see below Screenshot.

User-added image