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
MattMet86MattMet86 

@mention - ConnectAPIHelper not working

The APEX Dev guide says that you can use a helper method to simplify doing @mentions in chatter posts. I can't get the helper mothod to work. I am getting an error using the example code from the github site. 

Dev Guide:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectapi_examples_post_feed_element_mention.htm
Link to helper on github:
https://github.com/forcedotcom/ConnectApiHelper

Code:
ConnectApi.FeedItem fi = ConnectApiHelper.postFeedItemWithMentions(Network.getNetworkId(), 'me', 'Hey there {005D00000015tjz}, how are you?');
Error Message:
Illegal assignment from ConnectApi.FeedElement to ConnectApi.FeedItem
 
Pankaj_GanwaniPankaj_Ganwani
Hi Matt,

As per the shared documentation, the second parameter should either be the Id of a group or user or record. Can you supply a valid Id as second parameter and then try?
MattMet86MattMet86
I tried to change the 'me' to a chatter group ID and it still doesn't work. 

 
Pankaj_GanwaniPankaj_Ganwani
Hi Matt,

I checked out the class and found that its return type is set to connectapi.FeedElement instead of connectapi.FeedItem. I have updated your code accordingly:
 
ConnectApi.FeedElement fi = ConnectApiHelper.postFeedItemWithMentions(Network.getNetworkId(), 'me', 'Hey there {005D00000015tjz}, how are you?');

Make sure you supply the correct chatter group Id or record Id or User Id. 
MattMet86MattMet86
Thanks, this was pointed out by someone on the github site as well. I am now trying to figure out how to also utilize the "RelatedRecordId" field in the post so I can link a WorkThanks record to the chatter post. Any ideas? *Matt Metzinger* Salesforce Admin & Developer| BCInsourcing| 6363 College Blvd Ste 500| Overland Park, KS 66211 | ( 913.652.2087| * : mmetzinger@bcinsourcing.com
Raviraj S 1Raviraj S 1
Hi Pankaj,

I am implementing chatter post with rich text and inline images. The result of the code is a simple text message. I am able to post the message but I am not viewing the image. Can you please help me with img Id. Acutally I want to attach a badge image. How it can be done??? How to take the img Id?
ConnectApi.FeedElement fi = ConnectApiHelper.postFeedItemWithRichText(Network.getNetworkId(),
				recipientId, 'Have you seen this <b>gorgeous</b> view? {img:0W01a0000009IM3CAM}');