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?

  • The solution per the Salesforce docs is to enable the Guest user with permissions for chatter. The documentation is here: docs.releasenotes.salesforce.com/en-us/summer14/release-notes/… This option, however, didn't quite work for me, so I'm curious if we also have to use the Connect API in some fashion to add the member to a group. Oct 8, 2014 at 21:58
  • I don't know of a way to give the permission, but I do know that to insert EntitySubscription as a communities user I needed to execute the apex doing the insert in a class "without sharing". My guess is that this would also work in your case. Oct 8, 2014 at 22:30

2 Answers 2


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...

  • Scheduling an apex job to process sobjects that you insert might work, but the delay on that is going to be however often you can make your scheduled apex job run. Jan 29, 2016 at 17:20
  • 1
    Thanks @BritishBoyinDC! Can't believe it is this difficult to add chatter users to groups via public guest user; really had hoped without sharing would have sufficed in the apex class.
    – Doug Ayers
    Sep 23, 2016 at 3:58

I do this very thing with an after insert trigger on User, which then creates the CollaborationGroupMember. Coming in Winter '15 also is the ability to trigger on NetworkMember:


Either way in both cases for me, the trigger is being executed by the user assigned to the registration handler and not the guest. If for some reason that does not work, I can confirm that it works if the trigger calls a class without sharing, at least from a user trigger.

  • Doesn't the after insert trigger still run in the context of the guest user? Or are you doing something special like kicking off a future call, or setting the OwnerId or something? Could you post an Apex snippet perhaps? Oct 8, 2014 at 23:18
  • In my case, I'm using self-registration tied to an Auth Provider. The OAuth Auth Provider flow runs in the context of a specific internal user.
    – greenstork
    Oct 8, 2014 at 23:26
  • Ah. My case, and sounds like the authors case as well stems from Self Registration via a public site / guest user. Oct 8, 2014 at 23:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .