Post on Users/Records/Groups using Apex Salesforce

Apex Oct 12, 2014

In ordert to post to a User(@mention is not possible here) or a group we need to use FeedItem Apex Class, so here are the properties of the FeedItem Class

  1. Body: Text/Content of Post, mandatory if Type is TextPost
  2. ParentId: Record Id of the Record/User/Group to post
  3. Title: The title of the FeedItem. When the Type is LinkPost, the LinkUrl is the URL and this field is the link name
  4. Type: Link Post / Text Post and many
  5. Visibility: AllUsers/ Internal Users(by default)

NOTE: If Visibilty set over Internal Users then Community Users can't see it, so AllUsers enables access to both Internal and Community Users

Frequent Use Cases:

To Post Over Object Records, standard or custom object RecordId

FeedItem f = new FeedItem();
f.ParentId = <RecordId>;
f.Body = <Sample Text message>;
insert f;

To Post Over Chatter Group,

FeedItem f = new FeedItem();
f.ParentId = <GroupId>;
f.Body = <Sample Text message>;
insert f;

To Post Link Post Over Record/Group,

FeedItem f = new FeedItem();
f.Type = 'LinkPost';
f.Title = 'FeedBack Url';
f.ParentId = <RecordId/GroupId>;
f.LinkUrl = <URL of the Record>;
insert f;

NOTE:
For more Information on FeedItem Object capabilites, click here

Phanindra Mangipudi

Salesforce, Lightning Web Componets, Node.Js, Angular 2+, Bootstrap