2

is it possible to create a chatter FeedItem with a sites user with public access, is there any workaround to get this done?

I tried to insert it with "insert" and also with the ConnectApi but I got the same error message: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Entity is read-only: FeedItem: [].

it works with the standard salesforce user but not by creating the item through a salesforce sites user with public access.

    FeedItem                                        FInew                           = new FeedItem();
                                                    FInew.parentId                  = qu.Id;
                                                    FInew.Body                      = FeedBody;
    insert                                          FInew;

or:

ConnectApi.ChatterFeeds.postFeedItem( null, ConnectApi.FeedType.Record, string.ValueOf(ALI.Id), FeedBody);

4 Answers 4

2

In addition to the suggestions by BritishBoyinDC, an easier way would be by inserting the entries from the public site into a custom object. Then have a scheduled class pick up the messages from the custom object and post for chatter feed. This, however, would not be real-time. The scheduled job at best can run once every hour.

1

I found the best workaround for my issue.

I wrote the body of the feeditem into a custom field on the parentobject of the feeditem. Then I activated the feedtracking for this field and the feedtracking will create a feedItem automatically with the "sites user". In the standard chatter view you can see that it is an automated feedtracking feed but with a custom visualforce page it is possible to design it the way I want!!

For me this result is ok with and very easy to achieve.

1
  • This is a cool approach, but keep in mind that feed tracked changes are automatically deleted by the system after 45 days unless they have likes or comments. See help.salesforce.com/apex/…
    – alouie
    Commented Dec 12, 2014 at 23:13
1

Short answer...no. I asked the product team about it, and I didn't get the sense it was on road map either which is a shame - I have several projects where it would be useful.

As for workarounds, you need to be using a user who does have write access (obviously) - the ways I have got around it is to either

  1. Send the information to an email to salesforce web service (either with the information in the email, or just an Id of record you created with the info you need in the subject line that you can then query for to get the information) because that will then run in the context of the running user for that email service
  2. Have the code for a controller for a page on the public site login as a user in your sf system who does have write access to chatter and then use that logged in user to write to Chatter

Clunky workarounds for sure, but I don't know of anther way I'm afraid...

1

Another way would be to use feed item trigger and make the chatter feed accessible to everyone.

trigger FeedItemTrigger on FeedItem (before insert) {

    for(FeedItem fi:Trigger.new){
        fi.NetworkScope='AllNetworks';
        fi.Visibility='AllUsers'; 
    }

}

You must log in to answer this question.

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