function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VidhyaVidhya 

CollaborationGroupMemberRequest

Hi,

 

I am writing apex code to create group membership request by some user say ABCD to a private group - TestGrp.

  

My scenario is:


There is a private group(TestGrp) to discuss about an Opportunity - Opp_1.  People who are willing to join the group, post a chatter feed on Opp_1 record with a keyword say: '!JoinMe'. So I am writing a trigger on FeedItem. If any post on Opp_1 record contains text '!JoinMe', I am creating a group membership request with the userid of the person who posted his willingness to join the group.

 

The request should ideally go to the owner of the private group wher he can decide to approve/decline the request.

The owner of the private group will be informed by email as per this link.

http://www.salesforce.com/us/developer/docs/api/index_Left.htm#CSHID=sforce_api_objects_collaborationgroupmemberrequest.htm|StartTopic=Content%2Fsforce_api_objects_collaborationgroupmemberrequest.htm|SkinName=webhelp

 

This is the code below for what I am trying to achieve.

 

CollaborationGroupMemberRequest req = new CollaborationGroupMemberRequest();
req.CollaborationGroupId = grpId;  // Private group Id
req.RequesterId = userId;    // ABCD Id (the one who posted '!JoinMe' in the Opp_1 record chatter)
insert req;

 

But I am getting the following error:
first error:INVALID_CROSS_REFERENCE_KEY, You can only request group membership for yourself.:[RequesterId]:

 

Is there any workaround in requesting the group membership for someone else through apex code?
Please clarify.

  

Kind Regards,

Vidhya

ChrisOctagonChrisOctagon

Sorry unfortunately you cannot make requests on someone else's behalf.

 

However, since some users can just add folks to a group, you could avoid this issue by doing that directly instead of using a request, I think? Maybe you could use a custom object to track the requests in this case.

VidhyaVidhya

Hi Chris,

 

Thanks for confirming that we cannot make requests on someone else's behalf!!

We will have to figure another approach.

 

Thanks,

Vidhya