I have a Map where I put a String and a Decimal. Both of these fields are updated based on the day of the week. The String field can be converted into a date field since it's populated by the day, month and year of the day the corresponding Decimal field has been modified.
For example : attendanceRate_2__c modified on 10-28-2019 techDayMonthYear_2__c will be populated with 10282019
AttendanceRate_3__c modified on 10-29-2019 TechDayMonthYear_3__c will be populated with 10292019
The 'AttendanceRate_' + weekDay + '__c' fields are populated thanks to the day of the week. 2 for monday, 3 for tuesday ect.
I'm changing dynamically the weekDay in my apex code but the issue is that the new value replace the one that was put in the Map a week prior.
attendanceRate_2__c value on 10-28-2019 will be replaced by the value of attendanceRate_2__c on 11-04-2019
Here's my code:
Map<Integer, Map<String, Decimal>> workedDaysByMonth = new Map<Integer, Map<String, Decimal>>();
List<AttendanceRate__c > allAttendanceRates = [SELECT Id, User__c, AttendanceRate_2__c, AttendanceRate_3__c,
AttendanceRate_4__c, AttendanceRate__c, AttendanceRate_6__c,
techDayMonthYear_2__c, techDayMonthYear_3__c, techDayMonthYear_4__c,
techDayMonthYear_5__c, techDayMonthYear_6__c, Tech_External_Id__c
FROM AttendanceRate__c
WHERE User__c = :this.u.Id];
for(AttendanceRate__c ar: allAttendanceRates){
for(Integer weekDay = 2; weekDay <= 6; weekDay ++){
workedDaysByMonth.put(weekDay, new Map<String, Decimal>{ (String) tp.get('techDayMonthYear_' + weekDay + '__c') => (Decimal) getNotNullValue(tp.get('AttendanceRate_'+ weekDay + '__c'))});
}
}
I don't know what I'm doing wrong...