Background:
I need some sort of "Category" option for our Collaboration Groups for our community, and Salesforce doesn't offer custom fields or categories of any sort on CollaborationGroup object.
To combat this problem, I've created a Custom Object (Community_Group_Category__c
) with the following fields:
Category__c
(Picklist)Active__c
(Boolean)Collaboration_Group_Id__c
(Text, 18 digits unique case sensitive, holds related CollaborationGroup Id)- Could not be lookup since CollaborationGroup isn't available for lookup relationships.
I'm trying to create a map of type Map<String,List<CollaborationGroup>>
where Category__c
from Community_Group_Category__c
is the String
key, and the list of CollaborationGroup
is any group related to that Category__c
(using Collaboration_Group_Id__c
on Community_Group_Category__c
object).
I've been thinking about this for a few hours and keep changing my map structures to try to accommodate this but am having trouble visualizing how to get my intended end result. Thought maybe someone else can help stoke this fire and get me on the right track.
Here is my latest attempted code, I've built a Map<String,List<Community_Group_Category__c>>
but now I'm unsure of how (if at all) I can use this map to my advantage while looping through CollaborationGroup
and attempting to build another map of type <String,List<CollaborationGroup>>
where the String is Category__c from my custom object - The Id's that I want to match to CollaborationGroups while looping are in the .values()
of the catNameToCatMap
map collection:
@AuraEnabled
public static Map<String, List<CollaborationGroup>> getCategories(){
Set<String> groupCatSet = new Set<String>();
Map<String,List<Community_Group_Category__c>> catNameToCatMap = new Map<String,List<Community_Group_Category__c>>();
Map<String,List<CollaborationGroup>> catNameToGroupMap = new Map<String,List<CollaborationGroup>>();
for(Community_Group_Category__c cgc : [SELECT Id,Name,Active__c,Category__c,Collaboration_Group_Id__c FROM Community_Group_Category__c]){
if(cgc.Active__c){
if(!catNameToCatMap.containsKey(cgc.Category__c)){
catNameToCatMap.put(cgc.Category__c,new List<Community_Group_Category__c>());
}
catNameToCatMap.get(cgc.Category__c).add(cgc);
}
}
System.debug('MM catNameToCatMap KeySet: ' + catNameToCatMap.keySet());
System.debug('MM catNameToCatMap Values: ' + catNameToCatMap.values());
for(CollaborationGroup cg : [SELECT Id,Name,MemberCount,CollaborationType,Description,CanHaveGuests,NetworkId FROM CollaborationGroup WHERE CollaborationType = 'Public']){
// How Should I build a Map of cgc.Category__c,List<CollaborationGroup>> ??
}