I am capturing YouTube URLs in a Custom object, and I want to post new submissions to a chatter group. But I also want to take advantage of the nice inline youtube player in Chatter Feeds, which I think means I need to create a FeedItem of type 'LinkPost' and set the URL of the linkpost to the YouTube URL (if I do that it works)
But…I want to post to a Chatter Group AND link back to the Record in my custom object.As far as I can see, the parent Id of the feed item has to be the Group Id to make it appear in that group's feed, or the recordid on the object I want relate the post to. So is there some way that I can set the linkURL = to my YouTube URL, post in a chatter group AND have that post have a link back to the record id where the video url is stored? Or get the embed feature to work in Chatter and set the URL back to my record?
Best Answer
You are correct on your first point - if you don't create a LinkPost then the feed item doesn't get sent to embed.ly for processing and the embedded player doesn't appear.
You are also correct that you can specify either a group or a record id as the parent id.
If you are looking to have the post appear in both the the group feed and the record feed, your only option is to duplicate the post.
If, however, you can live with a link back to the parent record in the post, you can simply embed this into the feeditem.body field.
I've tweaked one of my existing pieces of code to a simple visualforce page and controller. The page allows the user to enter a URL for a youtube video, a link title, the group to post to and the id of an opportunity the post is also related to:
and the controller takes this information and creates a link post to the group, but also adds a link to the opportunity:
The resulting post in the group feed is as follows:
The opportunity URL looks slightly odd as it is derived from a visualforce page, but it is a clickable link and you do end up on the correct opportunity page. Unfortunately you can't turn this into an anchor tag and provide a friendly name.