- External Community
- Chatter Group in External Community
- Apex Email Service trying to insert FeedItem related to Chatter Group
FeedItem fi = new FeedItem( parentId = 'chatter group id in external community', body = 'Hello World' ); insert fi;
The above code snippet fails when ran from Apex Email Service or Developer Console with error:
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: .
If I change the parentId to be 'chatter group id in internal community' then it works beautifully. But when it's a group that belongs to an external community then error.
I know that in Apex there is the ConnectApi and it has various
postFeedElement( communityId, ... ) methods that let you specify the
CommunityId. But my requirement is that I need to set the FeedItem.CreatedById to be someone other than the context user for my open source project Chatter Bot for Feeds.
The ConnectApi does not let you specify the author it instead defaults to the context user. Hence why I'm trying to do this with FeedItem and DML directly via a context user with "Insert System Field Values for Chatter Feeds" permission so that I can set the author of the post to whomever I want.
This concept works great in the internal community, but failing when the apex code tries to insert FeedItem whose parent is a group that belongs to a external community.