You need to sign in to do that
Don't have an account?
Error Method does not exist or incorrect signature: [MAP<Id,User>].add(Id, SOBJECT:User)
I'm trying to create a map from a query list I created so I can access it by Id - here's the relevant code:
List<User>userResults= new List<User>();
set<Id>userIds = new Set<Id>();
Map<Id,User>userData = new Map<Id,User>();
//code that fills user ids
//get the relevant user data
userResults=[SELECT Id,MyField1__c,MyField2__c FROM User WHERE Id in: userIds];
//put it into a map for easier access
for (User u : userResults){
userData.add(u.Id,u); //here's where the error is
}
My List is of type User, the for loop u value is of type User and my map is Id, User so why doesn't it work?
Replace userData.add(u.Id,u); with userData.put(u.Id,u);
All Answers
Replace userData.add(u.Id,u); with userData.put(u.Id,u);
As Middha said. Also, FYI, you can do the following:
yeah I guess it would help if I used the right method name! Too much time with sets and lists I guess...
Thanks for that quick response too
Garyb - thanks for that tip. I didn't think it would be smart enough to do something like that