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
RarLopzRarLopz 

Error : Invalid Type Iterating over a Map

Can some one plese assist? 

If you look at my wrapper class, there is an inner class EcPerformanceRecordList .I have declared a list<EcPerformanceRecordList>  for getting and setting values between controller and UI

When i try to create a map so that I have a list of EcPerformaceRecordList per User, I get an error when I declare the map as map<String,<list<EcPerformanceRecordList>>

How can i declare a Map and loop through this map so that I can count how many apps have been submitted per user.
e.g 
    UserID  Total  EC(Yes)     Date
    user1   12      4          06/12/2019
    user1   13      13         06/13/2019
    user2   35      24         06/18/2019
    user3   23      31         07/02/2019    
    user1   17       2          07/10/2019
    user3   12       3          07/10/2019

I am trying something like this 
Map<userid, list<ecRecordList>> mapname = newMap<userid, list<ecRecordList>> 

mapname.put(user1, <{user1 12 4 06/12/2019}, {user1 13 13 06/13/2019},{user1 17 2 07/10/2019} )

mapname.put(user2, <{ user2 35 24 06/18/2019}, {user1 13 13 06/13/2019},{user1 17 2 07/10/2019} ) and so on.

then for each user, i want to loop through the list and calculate the totals. 
 

Here's snippet of my code for reference.  


public with sharing class MyController {

		public list<MyWrapper> wrapper {get;set;}
    	public integer appTotal {get;set;} 
    	public integer mtdappTotal {get;set;} 
    	public integer previousmonthappTotal {get;set;} 
    	public integer idlplusmtdTotal {get;set;}
    	public integer idlpluspreviousmonthTotal {get;set;}
    	public integer caTotal {get;set;}
    	public integer ecmtdTotal {get;set;}
    	public integer ecpreviousmonthTotal {get;set;}
    	public integer ecEligibleYesMTDTotal {get;set;}
    	public integer ecEligibleYesPreviosMonthTotal {get;set;}
    	public set<String> userid {get;set;}
		public Map<String,list<EcPerformanceRecordList>> ecperuserMap {get;set;}
    
    	
    	@AuraEnabled(cacheable=true)
		public void getdeserialize() {
		
			try{
                string jsonresponse = 'SOME STRING'
			   
			 	
                wrapper = (list<MyWrapper>) JSON.deserialize(jsonresponse, list<MyWrapper>.class);
			 	
                
                // call the method that aggregates the MonthToDate app count, and PreviousMonth app count per user 
                getTotalECBookedByUser(wrapper);
               
              
		     	
			} catch (Exception e){
				system.debug('Error---->' +  e.getLineNumber() + e.getMessage());
				
			}
    	}
    
    	
    
    // This method calclates the total EC Booked current month and previous month by each user 
    public integer getTotalECBookedByUser(list<MyWrapper> wrapper) {
        	     
        
		Map<String,list<EcPerformanceRecordList>> ecperuserMap = new Map<String,list<EcPerformanceRecordList>>();  
		for(MyWrapper jw: wrapper){
            
            jw.ecpreviousmonthTotal=0;
			jw.ecmtdTotal = 0;   
        	// create a map of submitUserID and ECSubmittedRecordList 
			Map<String,list<EcPerformanceRecordList>> ecperuserMap = new Map<String,list<EcPerformanceRecordList>>();  
        	 
        	for (MyWrapper.EcPerformanceRecordList ec : jw.ecPerformanceRecordList) {
            	
				if(ecperuserMap.containsKey(ec.submitUserID)){
				
					 ecperuserMap.get(ec.submitUserID).add(ec);

				}else {
				
					ecperuserMap.put(ec.submitUserID,ec);
				}
				          	  
            }
        }
		
		// loop through the map ecperuserMap and count the total apps submitted by each user this month and previous month 
		
		
        
        return ecpreviousmonthTotal;
        return ecmtdTotal;
	
    }
    
  
     
}




------------------------Wrapper Class ------------------


public class MyWrapper {
@AuraEnabled	
    public List<CaPerformanceRecordList> caPerformanceRecordList{get;set;}
    public List<EcPerformanceRecordList> ecPerformanceRecordList{get;set;}
    public Map<String,List<EcPerformanceRecordList>> ecPerUser {get;set;}
    public integer appTotal{get;set;}
    public integer mtdappTotal {get;set;} 
    public integer previousmonthappTotal {get;set;} 
    public integer idlplusmtdTotal {get;set;}
    public integer idlpluspreviousmonthTotal {get;set;}
    public integer caTotal {get;set;}
    public integer ecmtdTotal {get;set;}
    public integer ecpreviousmonthTotal {get;set;}
    public integer ecEligibleYesMTDTotal {get;set;}
    public integer ecEligibleYesPreviosMonthTotal {get;set;}
    public string name {get;set;}
    public integer data {get;set;}
    public integer data1 {get;set;}		// bar chart EC
    public string ecname {get;set;}  // bar chart EC 
    public integer ecdata {get;set;} // bar chart EC 
    public string ecname1 {get;set;}  // bar chart EC 
    public integer ecdata1 {get;set;} // bar chart EC 
    
     
   
	public class EcPerformanceRecordList {
		public String DealerID{get;set;}
		public String submitUserID{get;set;}
		public String bookedDate{get;set;}
		public String ecEligible{get;set;}
		public Integer caBookedCount{get;set;}
		public Integer ecBookedCount{get;set;}
       
        
	}
	
    
	public class CaPerformanceRecordList {
		public String DealerID{get;set;}
		public String dealerName{get;set;}
		public String reportingPeriod{get;set;}
		public String financeSourceIntegrationTypeCode{get;set;}
		public String idlPlus{get;set;}
		public String creditApplicationSourceCode{get;set;}
		public Integer submissionCount{get;set;}
    }
    

}

 
Best Answer chosen by RarLopz
Ajay K DubediAjay K Dubedi
Hi RarLopz,
Replace your method getTotalECBookedByUser's part in which you fill the map by this code:
Map<String,list<EcPerformanceRecordList>> ecperuserMap = new Map<String,list<EcPerformanceRecordList>>();  
for(MyWrapper jw: wrapper)
{
    jw.ecpreviousmonthTotal = 0;
    jw.ecmtdTotal = 0;   
    // create a map of submitUserID and ECSubmittedRecordList 
    
    Map<String, List<EcPerformanceRecordList>> ecperuserMap = new Map<String, List<EcPerformanceRecordList>>();  
     
    for (MyWrapper.EcPerformanceRecordList ec : jw.ecPerformanceRecordList) {
        
        if(!ecperuserMap.containsKey(ec.submitUserID)){
        
            ecperuserMap.put(ec.submitUserID, new List<EcPerformanceRecordList>());
        } 
        else {
        
            ecperuserMap.get(ec.submitUserID).add(ec);
        }
                      
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks,
Ajay Dubedi

All Answers

Ajay K DubediAjay K Dubedi
Hi RarLopz,
Replace your method getTotalECBookedByUser's part in which you fill the map by this code:
Map<String,list<EcPerformanceRecordList>> ecperuserMap = new Map<String,list<EcPerformanceRecordList>>();  
for(MyWrapper jw: wrapper)
{
    jw.ecpreviousmonthTotal = 0;
    jw.ecmtdTotal = 0;   
    // create a map of submitUserID and ECSubmittedRecordList 
    
    Map<String, List<EcPerformanceRecordList>> ecperuserMap = new Map<String, List<EcPerformanceRecordList>>();  
     
    for (MyWrapper.EcPerformanceRecordList ec : jw.ecPerformanceRecordList) {
        
        if(!ecperuserMap.containsKey(ec.submitUserID)){
        
            ecperuserMap.put(ec.submitUserID, new List<EcPerformanceRecordList>());
        } 
        else {
        
            ecperuserMap.get(ec.submitUserID).add(ec);
        }
                      
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks,
Ajay Dubedi
This was selected as the best answer
Deepali KulshresthaDeepali Kulshrestha
Hi RarLopz,

- I read your problem and implemented it in my Org and it is working fine.
- Please use the below code [Solved] : -
-------------- Apex Controller------- -----
public with sharing class MyController {

    public list<MyWrapper> wrapper {get;set;}
    public integer appTotal {get;set;}
    public integer mtdappTotal {get;set;}
    public integer previousmonthappTotal {get;set;}
    public integer idlplusmtdTotal {get;set;}
    public integer idlpluspreviousmonthTotal {get;set;}
    public integer caTotal {get;set;}
    public integer ecmtdTotal {get;set;}
    public integer ecpreviousmonthTotal {get;set;}
    public integer ecEligibleYesMTDTotal {get;set;}
    public integer ecEligibleYesPreviosMonthTotal {get;set;}
    public set<String> userid {get;set;}
    public Map<String,list<EcPerformanceRecordList>> ecperuserMap {get;set;}


    @AuraEnabled(cacheable=true)
    public void getdeserialize() {

        try{
            string jsonresponse = 'SOME STRING';

            wrapper = (list<MyWrapper>) JSON.deserialize(jsonresponse, list<MyWrapper>.class);

            // call the method that aggregates the MonthToDate app count, and PreviousMonth app count per user
            getTotalECBookedByUser(wrapper);

        } catch (Exception e){
            system.debug('Error---->' +  e.getLineNumber() + e.getMessage());

        }
    }

    // This method calclates the total EC Booked current month and previous month by each user
    public integer getTotalECBookedByUser(list<MyWrapper> wrapper) {


        Map<String,list<EcPerformanceRecordList>> ecperuserMap = new Map<String,list<EcPerformanceRecordList>>();
        for(MyWrapper jw: wrapper){

            jw.ecpreviousmonthTotal=0;
            jw.ecmtdTotal = 0;
            // create a map of submitUserID and ECSubmittedRecordList
            for (EcPerformanceRecordList ec : jw.ecPerformanceRecordList) {

                if(ecperuserMap.containsKey(ec.submitUserID)){

                    ecperuserMap.get(ec.submitUserID).add(ec);

                }else {
                    ecperuserMap.put(ec.submitUserID, new List<EcPerformanceRecordList>());

                    ecperuserMap.get(ec.submitUserID).add(ec);
                }

            }
        }
        // loop through the map ecperuserMap and count the total apps submitted by each user this month and previous month
        return ecpreviousmonthTotal;
        return ecmtdTotal;

    }

public class MyWrapper {
    @AuraEnabled
    public List<CaPerformanceRecordList> caPerformanceRecordList{
        get;set;
    }
    @AuraEnabled
    public List<EcPerformanceRecordList> ecPerformanceRecordList{
        get;set;
    }
    @AuraEnabled
    public Map<String, List<EcPerformanceRecordList>> ecPerUser {
        get;set;
    }
    @AuraEnabled
    public integer appTotal{
        get;set;
    }
    @AuraEnabled
    public integer mtdappTotal {
        get;set;
    }
    @AuraEnabled
    public integer previousmonthappTotal {
        get;set;
    }
    @AuraEnabled
    public integer idlplusmtdTotal {
        get;set;
    }
    @AuraEnabled
    public integer idlpluspreviousmonthTotal {
        get;set;
    }
    @AuraEnabled
    public integer caTotal {
        get;set;
    }
    @AuraEnabled
    public integer ecmtdTotal {
        get;set;
    }
    @AuraEnabled
    public integer ecpreviousmonthTotal {
        get;set;
    }
    @AuraEnabled
    public integer ecEligibleYesMTDTotal {
        get;set;
    }
    @AuraEnabled
    public integer ecEligibleYesPreviosMonthTotal {
        get;set;
    }
    @AuraEnabled
    public string name {
        get;set;
    }
    @AuraEnabled
    public integer data {
        get;set;
    }
    @AuraEnabled
    public integer data1 {
        get;set;
    }
    // bar chart EC
    @AuraEnabled
    public string ecname {
        get;set;
    }
    // bar chart EC
    @AuraEnabled
    public integer ecdata {
        get;set;
    }
    // bar chart EC
    @AuraEnabled
    public string ecname1 {
        get;set;
    }
    // bar chart EC
    @AuraEnabled
    public integer ecdata1 {
        get;set;
    }
    // bar chart EC

}

public class EcPerformanceRecordList {
    @AuraEnabled
public String DealerID{get;set;}
    @AuraEnabled
public String submitUserID{get;set;}
    @AuraEnabled
public String bookedDate{get;set;}
    @AuraEnabled
public String ecEligible{get;set;}
    @AuraEnabled
public Integer caBookedCount{get;set;}
    @AuraEnabled
public Integer ecBookedCount{get;set;}
}

public class CaPerformanceRecordList {
    @AuraEnabled
public String DealerID{get;set;}
    @AuraEnabled
public String dealerName{get;set;}
    @AuraEnabled
public String reportingPeriod{get;set;}
    @AuraEnabled
public String financeSourceIntegrationTypeCode{get;set;}
    @AuraEnabled
public String idlPlus{get;set;}
    @AuraEnabled
public String creditApplicationSourceCode{get;set;}
    @AuraEnabled
public Integer submissionCount{get;set;}
}

}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
RarLopzRarLopz
Thank you to both of you Deepali and Ajay Dubedi.