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
Christina WallaceChristina Wallace 

Chatter Post on behalf of Someone.

I' m banging my head.  I have got a button to allow Leaders to blast a Chatter post when we have updates.  However to make it easier on our users to get it, we are having them follow a User that just blast these update.

The Leaders are admins (as am I) and have it checked to allow "Insert System Field Values for Chatter Feeds" in our profile and in the code I have

   
        FeedItem post = new FeedItem();
        String s = 'THe Message';
        post.ParentId = landingChatterGroup.Id;
        System.debug('Concierge.Id ' + Concierge.Id);
        post.createdById = Concierge.Id;
        post.Body =s;
        post.Type = 'TextPost';
       
    insert post;

I am getting INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: [

What am I missing?  The user is a Manager in the chatter group I am trying to add the post to.
Best Answer chosen by Christina Wallace
Nevlyn DSousa TicloNevlyn DSousa Ticlo
Well,

This is not a limitation exactly. You have to pass "Current Community Id" in "NetworkScope" field of FeedItem. You can refer to the below link for details
https://help.salesforce.com/apex/HTViewSolution?id=000187667&language=en_US

Let me know if this works.

All Answers

Nevlyn DSousa TicloNevlyn DSousa Ticlo
Hi Christine,

Just to confirm, landingChatterGroup is the Chatter Group that you are trying to put the FeedItem into correct?
What is Concierge? Is that a User/Public Group? Do you have access to that? 

Try commenting out the post.createdById and doing the insert first. If insert succeeds then its probably that you do not have access to the Concierge group.
Christina WallaceChristina Wallace
landingChatter is a Public Chatter group.  Concierge is the User that I am trying to create the post by.  I have double checked that my Lookups are getting values.
 
Christina WallaceChristina Wallace
  List<CollaborationGroup> cgs = [SELECT Id, Name FROM CollaborationGroup WHERE Name = 'Vyne General Chatter'];
        User Concierge = new User();
        
        
        //get LandingChatter
        if (cgs.size() > 0) {
            landingChatterGroup = cgs.get(0);
        } else {
            landingChatterGroup = new CollaborationGroup();
        }
        
        //get User
        List <User> ConciergeSearch = [select id, name from user where firstname = 'Veranda' and LastName='Concierge'];
         if (ConciergeSearch.size() > 0) {
            Concierge = ConciergeSearch.get(0);
        } else {
            Concierge = new User();
        }
        
        
        FeedItem post = new FeedItem();
        String s = 'THe Message';
        post.ParentId = landingChatterGroup.Id;
        System.debug('Concierge.Id ' + Concierge.Id);
        post.createdById = Concierge.Id;
        post.Body =s;
        post.Type = 'TextPost';
       
        insert post;
        
Nevlyn DSousa TicloNevlyn DSousa Ticlo
The user that you are trying to create the FeedItem with, is he/she part of the chatter group? Is the user a Community/Portal User by any chance? 
If the above two dont hold, try adding this line
post.Visibility = 'AllUsers'

let me know if it works
Christina WallaceChristina Wallace
The user is a Community Portal user that is a Manager on this Community Chatter group..

but I think the issue is my group is a Community Chatter group.  I was able to get it to post to my Internal Salesforce Chatter via myself and to have this user (Concer.) post to me on my Salesforce Chatter.  How come I have a feeling this is going to be a limitation issue with Community Chatter?   
Nevlyn DSousa TicloNevlyn DSousa Ticlo
Well,

This is not a limitation exactly. You have to pass "Current Community Id" in "NetworkScope" field of FeedItem. You can refer to the below link for details
https://help.salesforce.com/apex/HTViewSolution?id=000187667&language=en_US

Let me know if this works.
This was selected as the best answer
Christina WallaceChristina Wallace
That was it.  I needed to set Network Scope.  Thanks!  I had looked and could find this.