[SalesForce] How to add permission to Salesforce Chatter Collaboration Group sObject

I have communities enabled in my org and i have a class which will auto add the new registered member to a chatter group.

    CollaborationGroupMember cand = new CollaborationGroupMember(CollaborationGroupId=groupId, MemberId=UserId);
    try {
        insert cand;
        System.debug('Success insert cand >>'+ cand );
    } catch (DMLException e) {
        System.debug('There was an error with the invite: '+e);
    }

but when i execute the code it give me this error -> "Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Entity is read-only: CollaborationGroupMember: []"

I am guessing my communities default Guest account doesnt have the right to insert new collaborationgroupmember record. is there a way to extend this permission for this guest profile?

Best Answer

As far as I know, there is no way to extend that to a guest user - I've asked the Chatter folks a while back, and they confirmed that was the case. I'll ask again next week, but there didn't seem to be any plans to change it anytime soon.

The ConnectAPI doesn't help you because it only runs in the context of the current user.

A crude work around I have used in the past was to create an apex email service, and then send an email with the user id to that service...because the service runs under the context of the running user for that service, it was able to write to a Chatter group etc. I have also seen code that executes a login as a different user with r/w permissions to Chatter...

Related Topic