0

I have a Map inside a Map where I want to put values of type String (TechDayMonthYear_2__c) and Decimal (AttendanceRate_2__c). But I get 2 errors "Invalid type: tp.AttendanceRate_2__c" and "Invalid type: tp.TechDayMonthYear_2__c and don't understand why since it's the right types for both fields. Here is my code :

Map<Integer, Map<String, Decimal>> workedDaysByMonth =  new Map<Integer, Map<String, Decimal>>();
List<Taux_Presence__c> allAttendanceRates = [SELECT Id, User__c, AttendanceRate_2__c, AttendanceRate_3__c, 
                                                     AttendanceRate_4__c, AttendanceRate_5__c, AttendanceRate_6__c, 
                                                     TechDayMonthYear_2__c, Tech_Mois_Creation_3__c, Tech_Mois_Creation_4__c,
                                                     Tech_Mois_Creation_5__c, Tech_Mois_Creation_6__c, Tech_External_Id__c
                                                     FROM Taux_Presence__c 
                                                     WHERE User__c IN :this.reportsByUserId.keySet()];
        for(AttendanceRate__c tp : allAttendanceRates){
            for(Integer dayMonthYear : daysNumbersInQuarter.keySet()){
                workedDaysByMonth.put(dayMonthYear, new Map<tp.TechDayMonthYear_2__c, tp.AttendanceRate_2__c>());

            }
        }            
1
  • In addition to Adrian's answer, your code won't compile because allAttendanceRates's type does not match your for loop.
    – David Reed
    Commented Oct 29, 2019 at 15:55

1 Answer 1

3

The types for your key and value on your inner map are String and Decimal, but you instead put tp.TechDayMonthYear_2__c and tp.AttendanceRate_2__c, which are not even types, hence the compile error. Your inner map should instead be:

new Map<String, Decimal> { tp.TechDayMonthYear_2__c => tp.AttendanceRate_2__c }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .