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
sgsssgss 

Write a SOQL query to find total number of Lead records by status by Lead Source. Store this information in map and display the same. (Hint: map<string,map<string,integer>>)

Can anyone help with the code for
Write a SOQL query to find total number of Lead records by status by Lead Source. Store this information in map and display the same. (Hint: map<string,map<string,integer>>)
Raj VakatiRaj Vakati
use this code
 
List<Lead> leads =[Select Id , LeadSource,Name from Lead] ; 
map<string,map<string,integer>> mapOf  = new map<string,map<string,integer>>(); 

for(Lead  l :leads){
    if(mapOf.containsKey(l.LeadSource)) {
        map<string,integer> mapLsi = mapOf.get(l.LeadSource);
        Integer val = mapLsi.get(l.LeadSource) ; 
        val++ ; 
        mapLsi.put(l.LeadSource ,val) ;
        mapOf.put(l.LeadSource , mapLsi);
    } else {
        Map<String,Integer>  mmm=  new Map<String,Integer>(); 
        mmm.put(l.LeadSource,1);
        mapOf.put(l.LeadSource,mmm);
    }
    
    
}

 
sgsssgss
Raj can you provide test class for above
Raj VakatiRaj Vakati
Use this code
 
@isTest
public class TestLeadTrigger
{
@isTest
public static void testLeadInsert ()
{
	Lead objLead = new Lead (LastName = 'Test', Email = 'test@gmail.com', mobilephone = '+1234567890', Company = 'Test company',LeadSource='web');
	insert objLead; 
	
	Lead objLead1 = new Lead (LastName = 'Test', Email = 'test@gmail.com', mobilephone = '+1234567890', Company = 'Test company',LeadSource='web');
	insert objLead1; 
	
	Lead objLead2 = new Lead (LastName = 'Test', Email = 'test@gmail.com', mobilephone = '+1234567890', Company = 'Test company',LeadSource='Email');
	insert objLead2; 
}
}

 
sgsssgss
The above code is not working