Last active
April 27, 2022 14:30
-
-
Save emoran/4ea945ec3db32cc8c06b to your computer and use it in GitHub Desktop.
Adding list values to apex map<String,List<Sobject>>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<Id, List<Id>> userRoleToUsers = new Map<Id, List<Id>>(); | |
for(User newUser : [SELECT UserRoleId FROM User LIMIT 50000]) { | |
if(userRoleToUsers.containsKey(newUser.UserRoleId)) { | |
List<Id> usersId = userRoleToUsers.get(newUser.UserRoleId); | |
usersId.add(newUser.Id); | |
userRoleToUsers.put(newUser.UserRoleId, usersId); | |
} else { | |
userRoleToUsers.put(newUser.UserRoleId, new List<Id> { newUser.Id }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think we can write above code as below: