I have a map which I want to sort the results in ASC order
Let's say that yearToDate is holding the below result
The result I have in yearToDate is
yearToDate::{Year 1=2023-09-15 00:00:00, Year 2=2024-03-15 00:00:00}
yearToDate = new Map<String, Decimal>();
and I am running the result to build another Map data
yearToDate = new Map<String, Date> ();
dateToDecimal = new Map<String, Decimal> ();
for (String eKey : yearToDate.keySet()) {
String key = 'Total ' + getMonthName(yearToDate.get(eKey)) + ' ' + yearToDate.get(eKey).year();
dateToDecimal.put(key, yearToSum.get(eKey));
}
public static String getMonthName(Date value)
{
return Datetime.newInstance(value, Time.newInstance(0, 0, 0, 0)).format('MMMM');
}
In the above example, I am getting the result as
dateToDecimal::{Total March 2024=12000.00, Total September 2023=6265.67}
The expected result would be like
dateToDecimal::{Total September 2023=6265.67, Total March 2024=12000.00}
I don't see any examples as well to sort this result in the correct order. Any help would be appreciated. Thank you