Some background of what I did so far, I took a set of Ids out of User that are 'PowerPartners', and with those Id's I search for them in Group Members. Now I have a groupList, and with that groupList I want to check and see if when a Lead is created if it is in that list. I'll post my code below, and the things I tried.. (Some are obviously wrong)
if(groupList.containsKey(ld.CreatedById)) --Method Does not exist or incorrect signature
if(groupList.get(ld.CreatedById)) --Method Does not exist or incorrect
if(groupList.contains(ld.CreatedById))--Method Does not exist or incorrect
if(groupList == ld.CreatedById) --Comparison arguments must be compatible types
Trigger
List<GroupMember>groupList = new List<GroupMember>([select GroupId,UserOrGroupId from GroupMember where UserORGroupID IN:pUserMap]);
System.debug('groupList '+groupList );
if(pUserMap != null){
//System.debug('Inside PartUserMap != null');
for(Lead ld: trigger.new){
if(groupList.containsKey(ld.CreatedById)){ //Need help here
LeadShare ldShare = new LeadShare (LeadId = ld.id, LeadAccessLevel = 'Edit');
leadShareList.add(ldShare );
}
}
}
Attribution to: EricSSH
Possible Suggestion/Solution #1
This is because your groupList is a list and the containsKey() method is for Maps not Lists
You have to change your first line of code 'query' to something like this :
Map<Id, GroupMember> groupMap = new Map <Id, GroupMember>();
for(GroupMember grp : [select GroupId, UserOrGroupId from GroupMember where UserORGroupID IN:pUserMap])
groupMap.put(grp.UserOrGroupId, grp);
Then this line of code should work just fine
if(groupMap.containsKey(ld.CreatedById))
Attribution to: melmoussaoui
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33731