How do we create a chatter group for a custom object. In that group I want to post feed comments and feed posts regarding to that particular custom object and display in that group.
[SalesForce] How do we create a chatter group for a particular object
Related Solutions
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:pageBlockButtons>
<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}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
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.parentId=groupId;
fItem.linkUrl=linkUrl;
fItem.title=linkTitle;
fItem.body=detail + ' Opportunity: ' + System.URL.getSalesforceBaseUrl().toExternalForm() + '/' + oppId;
insert fItem;
return null;
}
}
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.
Each Chatter FeedItem
can only have one parent record - and if you'd like these FeedItems
to show up in a record's chatter feed, e.g. using <chatter:feed entityId="{!recordId}"/>
, then you'll have to have the record be the parent of the FeedItem
. So, to be able to accomplish your intention - of having a record show up in both the Record's feed and a Group's feed, here are some thoughts on how to achieve this.
- (Probably the best way) Create 2 FeedItems with the same content, one whose ParentId is the Record, and one whose ParentId is the CollaborationGroup.
(If you must post just one FeedItem, and have to post it to the CollaborationGroup): on your Visualforce page, instead of showing a
<chatter:feed>
, which will just show just Chatter related to that record, you could use the<chatter:newsFeed>
tag instead. This will show all Chatter relevant for the running user. That way, if the running User is a member of the CollaborationGroup to which you posted the FeedItem, the running User will, when viewing this Visualforce page, see the recent Chatter posts for the CollaborationGroup, as well as any Chatter posts for the record in context, or Chatter posts directed at them.(If you must post just one FeedItem, and you can post it to the Record) If you can post the FeedItem to the Record, but don't want to create a duplicate FeedItem in the CollaborationGroup, but you still want all members of the CollaborationGroup to be updated when these FeedItems are posted to the Records in question, you could leverage / create Auto-Follow Rules (whether built on your own with Triggers or through one of the AppExchange apps that does this) to have all members of certain CollaborationGroups automatically follow these Records - that way, in their Chatter Feeds, they'll be guaranteed to see all of the FeedItem posts in question. Alternatively, you could have all followers of the Record automatically made members of the CollaborationGroup - depends on your situation.
Best Answer
I believe chatter groups can't be specific to an object or record only. One possible way to achieve this could be via Apex triggers i.e.