I want to save the below query into a Map<Id, String> like in the sentence below:
Map<Id, String> queuesMap = new Map<Id, String> ([SELECT Id, DeveloperName
FROM Group
WHERE Type = 'Queue' ]);
But, for some reason (?), when testing this in "Execute Anonymous Window", I am getting this error:
Line: 1, Column: 29
Invalid initializer type List<Group> found for Map<Id,String>: expected a Map with the same key and value types, or a valid SObject List
While doing some trial/error, I have tried the following, which does not return any error:
Map<Id, Group> queuesMap = new Map<Id, Group> ([SELECT Id, DeveloperName
FROM Group
WHERE Type = 'Queue' ]);
I need to end up having a Map<Id, String> because, eventually, my code has an apex method returning the key paired with a provided String (provided to the method).
How can I store the result of the above query (a List) into a Map<Id, String>?
Thank you.
Map<Id, String> queuesMap = new Map<Id, String>();
for(Group g : [SELECT Id, DeveloperName FROM Group WHERE Type = 'Queue']){
queuesMap.put(g.Id, g.DeveloperName);
}