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
sai harishsai harish 

Need help with Map !!

Hello,

I have two Lists of AggregateResults by month and I am using a where condition for Year so that I will get values from Month 1 to Month 12. I have created a Dummy formula field in my First object and made it to Zero. 

Is there a way to map months in both the Lists and get the Amount from second list and put it in the 1st List. The Amount in the first List will always be Zero. 
Thanks in advance!!
Public Class Test{

Public Void Test(){
List<AggregateResult> ar = [SELECT calendar_month(Forecast_Date__c) month, sum(Base_Line__c) Baseline, sum(Forecast__c)Forecast, sum(Actual__c)Actual, sum(Dummy_Amount_For_Chart__c)Amount From Revenue_Forecast__c WHERE calendar_year(Forecast_Date__c) = 2018 Group by calendar_month(Forecast_Date__c) ORDER BY calendar_month(Forecast_Date__c)];

List<AggregateResult> ar1 = [Select calendar_month(Close_Date__c) month, sum(Amount__c)Amount From Bid__c WHERE calendar_year(Close_Date__c) = 2018 GROUP BY calendar_month(Close_Date__c) ORDER BY calendar_month(Close_Date__c)];
}
}

 
Steven NsubugaSteven Nsubuga
You can create a Map with a String key for month, and Decimal value for Amount. Then you can iterate through your lists and populate the map as needed.