I'm trying to populate a list of Ids using a soql query but can't seem to get there.
Currently I have:
Public List <Id> listOfGroupIds (id userId) {
List <Id> returnListOfPublicGroupIds = new List <Id>();
List <GroupMember> groupMemberList =
[SELECT GroupId FROM GroupMember WHERE UserOrGroupId = : userId];
for (GroupMember gm : groupMemberList) {
returnListOfPublicGroupIds.add (gm.GroupId);
}
return returnListOfPublicGroupIds;
}
but I would like to do something more along the lines of
Public List <Id> listOfGroupIds (id userId) {
List <Id> returnListOfPublicGroupIds = new List <Id>();
return returnListOfPublicGroupIds =
[SELECT GroupId FROM GroupMember WHERE UserOrGroupId = : userId].GroupId;
}
The error is telling me I am assigning an id to a list of ids. Is there a way to populate this list without the for loop?