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
PrasadVRPrasadVR 

Can any one provide me some example for Maps ?

Hi ,

 

      Can any one provide me some sample example for Maps with Map<string,List<Id>> , exactly I am looking for Map which needs to be store all user names as a key and record ids related to that user as the values ?

Avidev9Avidev9

Lets say you want to store UserId and all the related lead Id in a map 

 

Map < String, List < Id >> userLeadMap = new Map < String, List < Id >> ();
for (Lead leadObj: [SELECT Id, Owner.Name FROM Lead]) {
    if (userLeadMap.get(leadObj.Owner.Name) == NULL) {
        userLeadMap.put(leadObj.Owner.Name, new List < Id > ());
    }
    userLeadMap.get(leadObj.Owner.Name).add(leadObj.Id);
}

 You can see its pretty simple :)