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

Workarounds for allowing site user to post chatter feeditem

Have a public site whose actions I would like to, through a trigger, create a chatter post. I know people have come to this issue before, i'm looking for good workarounds.

The first one I think of is having a batch to find the record of something the site user can update and having that batch schedule itself at the end. But I've seen this get very messy. The list of scheduled jobs gets very big and at some point you have the issue of a phantom job that prevents you from deploying code even in sandboxes. 

Another possible is to have an email service that accepts email sent from the site controller with the information of what post to create. I've never tried this before so not sure about any pitfalls asides from using email limit and it just being not nice.

Any other ideas/work arounds? Thanks.
You can create a Trigger also on the required action you can insert a record of FeedItem and relate it to the feeds of that particular record.

So,In your Trigger you should be looking at something like below :-

// Inserting a chatter feed    
    FeedItem post = new FeedItem();
    post.ParentId = <Id of record>;
    post.CreatedById = o.OwnerId;
    post.Body = '<Your Body>';
    post.Title = o.Name;

    insert post;

If this helps,please mark it as best answer to help others :)
Thanks but that would still be under context of the site user, which cannot create chatter posts. 
Yes that's right to be very precise there is an existing Idea for the same to allow the same :-

What I was thinking is to have insert a Custom object record from Site with all the info required to insert Chatter feed and then on the insert event write a Trigger on Custom object which would insert a FeedItem record and then in the Same trigger you can delete the custom object record if you don;t want to store the same.

Hope this helps !!
Sorry but I still don't see how your suggestion would work. A trigger on a custom object would still be under the context of the site user. I don't think adding another layer of triggers helps. Unless I am missing something in which case please explain. 
Edward Bates 10Edward Bates 10
If you store the Chatter Feed info in the Custom Object, and then run a scheduled job to post the chatter feed every 5 mins or so from the records in the custom object, this should work. Remember to delete the records once you have used them in the chatter post