3

I'm trying to write a trigger that awards badges to people and then posts them in a chatter post.

I've found this: https://help.salesforce.com/HTViewSolution?id=000199013&language=en_US

Which is very helpful, and gets me 90% of the way to where I need to be. It lets me create thanks, and badges and post then on FeedItems.

However, what it doesn't get me is the ability to do @mention calls within the body of the post.

I've been searching and searching over the past few hours, and it seems the only way to get @mentions in there is to use the ConnectApi.ChatterFeeds class (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_ConnectAPI_ChatterFeeds_static_methods.htm). This looked very promising, and it's not too hard to get a FeedItem with an @mention in the body.

But what appears to be missing is the ability to attach the badge using these classes.

I've been pouring over ConnectApi.FeedElementInput (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_input_feed_element.htm), and it seems that the "capabilities" section is what I should be using.

However, none of the capabilities on the input side (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_input_feed_element_capabilities.htm#apex_connectapi_input_feed_element_capabilitites) seem to be relevant to the assignment of work thanks and work badges.

When I use the connectApi to query an existing feed item, and export it to json, I get this in the capabilities section:

"enhancedLink":{
"description":"You are so great at this!", "icon":{
"height":75, "url":"myUrl", "width":75 }, "linkRecordId":null, "linkUrl":null, "title":"Awesome Selling!" }

Which is a reference to my badge. However, there is no "linkRecordId" set.

There is also no "enhancedLinkCapabilityInput" option when inputting FeedElements.

So I am somewhat at a loss, I'd like to be able to generate these badges, get then into posts, and do @mentions.

1 Answer 1

1

All of your findings are correct. I really wish that posting Thanks was supported in the ConnectApi Apex namespace so that you can directly make @mentions, but it isn't.

A couple of workarounds:

  1. After you post the feed item, post a comment with @mentions using ConnectApi.ChatterFeeds.postCommentToFeedElement().
  2. If the "Edit Feed Posts and Comments" feature is enabled for the users who are posting the Thanks messages, use ConnectApi.ChatterFeeds.updateFeedElement() to edit in the @mentions after you make the original post.
4
  • Hmmm, I actually tried option #2 yesterday, but I didn't think about setting the permissions. However, what kind of ramifications does having this permission have?
    – Evan
    Jun 22, 2015 at 16:51
  • Users will be able to edit their posts and comments in Chatter. It's pretty nice for correcting typos. The editing history is stored in the FeedRevision sObject in case you need to access it.
    – alouie
    Jun 22, 2015 at 21:58
  • 2
    So, with further investigation, it seems that this won't work. When I try to update this feed item with an @mention, it throws this error: ConnectApi.ConnectApiException: Body may only be updated on user generated posts. This seems to happen with or without the permission allowing them to edit their posts.
    – Evan
    Jun 23, 2015 at 13:42
  • Sorry, I overlooked that. Option #1 is the only feasible workaround that I can think of.
    – alouie
    Jun 23, 2015 at 17:21

You must log in to answer this question.

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