Search code examples
salesforceapexsoql

Salesforce apex collaborationgroup/collaborationgroupmember relationship?


I'm trying to get a list of collaboration groups and their associated members. I'm trying to do the following soql query but it does not recognise the CollaborationGroup.CollaborationGroupMembers relationship

List<CollaborationGroup> cgs = new List<CollaborationGroup>([Select OwnerId, Id, (select CollaborationGroupMember.MemberId from CollaborationGroup.CollaborationGroupMembers) From CollaborationGroup]);

Looking at the API, CollaborationGroupMembers has a CollaborationGroupId which is the ID of the associated CollaborationGroup, so the relationship should exist - can anyone tell me why it's not working?

Thanks

J

edit: I have figured this out the other way round (going from member to group (child to parent) rather than vice-versa) by doing the following:

List<CollaborationGroupMember> cgs = new List<CollaborationGroupMember>([select MemberId, CollaborationGroupMember.CollaborationGroup.OwnerId from CollaborationGroupMember where CollaborationGroupMember.CollaborationGroup.Name]);

However, I'd still like to know why I couldn't do it from parent to child as I was trying to in the first place?

Thanks


Solution

  • As per the documentation here, it's not having a relation from CollabarationGroup into CollabarationGroupMember. But as you have mentioned, it's having the relation in the otherway around, see this.

    So if you need to collect members from a particular group you can try

    SELECT MemberId FROM CollaborationGroupMember WHERE CollaborationGroupId='your_group_id'
    

    or filter it from CollaborationGroup.Name as you are already doing.