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
Vadivel MuruganVadivel Murugan 

Date for Same month

Hi All,

I have query last 90days record for opportuniy. I need to put monthwise record in map. For exmaple.

opportunity Created date - 12-12-2015
Opportunity Created date - 03-01-2016

The above opportunity stored in different maps. how to store it in maps. Any one know please reply to me.
So you are looking to create a map of opportunity month to list of opportunities?
Map<Integer, List<Opportunity>> oppMap = new Map<Integer, List<Opportunity>>();

for (Opportunity opp : [
    select CreatedDate
    from Opportunity
    where CreatedDate = LAST_N_DAYS:90
]) {
    Integer month = opp.createdDate.month();

    if (!oppMap.containsKey(month)) {
        oppMap.put(month, new List<Opportunity>());

NOTE: This code has not been tested and may contain typographical or logical errors