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?

1 Answer 1


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:

<apex:page controller="ChatterPostController">
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockButtons >
        <apex:commandButton value="Post" action="{!doPost}" />
      <apex:pageBlockSection columns="1">
         <apex:outputLabel value="Detail"/>
         <apex:inputText value="{!detail}" />
         <apex:outputLabel value="Link URL"/>
         <apex:inputText value="{!linkUrl}" />
         <apex:outputLabel value="Link Title"/>
         <apex:inputText value="{!linkTitle}" />
         <apex:outputLabel value="Opportunity ID"/>
         <apex:inputText value="{!oppId}" />
         <apex:outputLabel value="Group ID"/>
         <apex:inputText value="{!groupId}" />

and the controller takes this information and creates a link post to the group, but also adds a link to the opportunity:

public with sharing class ChatterPostController {

    public String detail {get; set;}
    public String linkUrl {get; set;}
    public String linkTitle {get; set;}
    public Id oppId {get; set;}
    public Id groupId {get;set;}

    public PageReference doPost()
        FeedItem fitem=new FeedItem();
        fItem.body=detail + ' Opportunity: ' + System.URL.getSalesforceBaseUrl().toExternalForm() + '/' + oppId;

        insert fItem;

        return null;

The resulting post in the group feed is as follows:

enter image description here

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.

  • That'll work - thanks! Seems odd you can't share a post between a record and group though...maybe in the next release... Commented Dec 10, 2012 at 17:15

You must log in to answer this question.

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