1

I'm needing to associate new SF Community Users to the proper Unlisted Chatter Group within their Community via trigger/triggerhandler. Hard Part is ChatterCollaborationGroup has no reference to Account, so I've created a workflow to create the groups via standard interface so that we have a set of records containing proper associations between group name and AccountId.

I've gotten as far in coding as having a map with Group Names associated to the proper Account ids and a second map associating the Group Names to group Ids. Names are set as keys because Id values are what I need to retrieve and parse. It looks something like this in psuedo code for clarity

GName2AccountIdMap   =  <ChatterGroupName , AccountId>
ChatterGroupIDMap    =  <ChatterGroupName , ChatterGroupId>

I need to iterate through these Matching on ChatterGroupName to create a 3rd Map resulting with:

Account2GroupIdMap  <AccountId , ChatterGroupId>

final statement in adding a user to a group to create a new CollaborationGroupMember is within a for loop using "member" as follows.

member.CollaborationGroupId = Account2GroupIdMap.get(user.AccountId); 

I just need help iterating over the first two maps to create the third.
It's a complicated use case, but really just a matter of knowing the right syntax to aggregate value sets for two maps into a third using AccountID as the KeySet and ChatterGroupID as the value set. Likely child's play for someone with more experience than I have. All help appreciated.

2

If I got it right:

for (String name : ChatterGroupIDMap.keySet()) {
 if (GName2AccountIdMap.containsKey(name)) {
   // do stuff with third map
   Account2GroupIdMap.put(GName2AccountIdMap.get(name), ChatterGroupIDMap.get(name));
 }
}
0
0

Hi something like this might work:

  //iterate over the keys of ChatterGroupIDMap
for (String name : ChatterGroupIDMap.keySet()) {
//check if GName2AccountIdMap contains key
 if (GName2AccountIdMap.containsKey(name)) {
   //add values to third map
   Account2GroupIdMap.put(GName2AccountIdMap.get(name), ChatterGroupIDMap.get(name));
 }
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.