You need to sign in to do that
Don't have an account?
RarLopz
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;} } }
Replace your method getTotalECBookedByUser's part in which you fill the map by this code:
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
Replace your method getTotalECBookedByUser's part in which you fill the map by this code:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
- I read your problem and implemented it in my Org and it is working fine.
- Please use the below code [Solved] : -
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.