Post on Users/Records/Groups using Apex Salesforce
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
- Body: Text/Content of Post, mandatory if Type is TextPost
- ParentId: Record Id of the Record/User/Group to post
- Title: The title of the FeedItem. When the Type is LinkPost, the LinkUrl is the URL and this field is the link name
- Type: Link Post / Text Post and many
- 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