9

I want to add Chatter feeds from Trigger and obviously I am going to implement this as Bulkified.

I have data in the following format.

Public Class ChatterFeedInfo
{
    public Id usermentionId {get;set;} // user records to which chatter feed will be @mentioned [@John Doe]
    public Id recordId {get;set;} // parent record id
    public String body {get;set;} // feed body
    public Id chatterGroupId {get;set;} // if not null  post this feed to Chatter Group
}

I get List<ChatterFeedInfo> chatterFeeds in my trigger but not sure how to implement this with 'Chatter in Apex'.

Please suggest.

2
  • 2
    I would imagine not - ConnectApi.ChatterFeeds.postFeedItem takes a String or a FeedItem, not a list. salesforce.com/us/developer/docs/apexcode/Content/… Commented Jun 5, 2013 at 17:06
  • if its true then its really sad and bad news :(, SFDC suggests that code should be bulkified but now I am stuck.
    – PK85
    Commented Jun 6, 2013 at 2:59

2 Answers 2

2

You can bulk insert to FeedItem directly in Apex, but unfortunately you cannot perform an @mention this way. Also, techtrekker is right about using the Connect API, it doesn't support multiple inserts at once.

Tell us a little about your implementation. You might be able to do this from another perspective. You mentioned doing this from a trigger. Is the trigger being fired from insert/update from custom code (i.e. VF/apex) or some other mechanism?

1
  • Not sure what the downvote was about. Only reason I didn't ask the question in a comment was because at the time I had no comment ability.
    – drakored
    Commented Jun 11, 2013 at 18:11
0

I am running into the same issue.

Similar to what you are doing, I have a pod data class to wrap Feed Items I want to post. I also created a shadow object, e.g. Chatter_Feed_Info__c.

In my trigger, I check how many DML statements remain. If I cannot insert all my Feed Items one at a time under the limit, I bulk create the shadow objects instead. Then I call a batch that posts the shadow Feed Items to Chatter 150 at a time.

Disclaimer: I haven't gotten to testing yet.

You must log in to answer this question.

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