No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Working with Feeds and Feed Items
How the Salesforce UI Displays Feed Items
To give customers a consistent view of feed items and to give developers an easy way to create UI, the Salesforce UI uses one layout to display every feed item, regardless of the feed item type. The layout always contains the same elements and the elements are always in the same position; only the content of the layout elements changes. If you stick to this structure, you won’t have to create a unique layout for every feed item type.
These are the feed item layout elements:- Actor (ConnectApi.FeedItem.actor)—A photo or icon of the creator of the feed item. (You can override the creator at the feed item type level. For example, the dashboard snapshot feed item type shows the dashboard as the creator.)
- Preamble (ConnectApi.FeedItem.preamble)—Provides context. The same feed item can have a different preamble depending on who posted it and where. For example, Gordon posted this feed item to his profile. If he then shared it to a group, the preamble of the feed item in the group feed would be “Gordon Johnson (originally posted by Gordon Johnson)” and the “originally posted” text would link to the feed item on Gordon’s profile.
- Body (ConnectApi.FeedItem.body)—All feed items have a body, but the body can be null, which is the case when the user doesn’t provide text for the feed item. Because the body can be null you can’t use it as the default case for rendering text. Instead, use the text property of the feed item’s preamble, which always contains a value.
- Auxiliary Body (ConnectApi.FeedItem.attachment)—The visualization of the attachment. There are multiple attachment types. For example, for a link post, the attachment is the link and name, for a poll, it’s the poll data. In Chatter in Apex, the attachment types are subclasses of ConnectApi.FeedItemAttachment. In Chatter REST API, the attachment types are exposed as response bodies with the name Feed Item Attachment: Name, for example, Feed Item Attachment: Link and Feed Item Attachment: Poll. Make sure your code has a default case that doesn’t display an auxiliary body if it doesn’t recognize the attachment type.
- Created By Timestamp (ConnectApi.FeedItem.relativeCreatedDate)—The date and time when the feed item was posted. If the feed item is less then two days old, the date and time are formatted as a relative, localized string, for example, “17m ago” or “Yesterday”. Otherwise, the date and time are formatted as an absolute, localized string.
Here’s another example of
a feed item in the Salesforce UI. This feed item’s auxiliary body contains a poll:
Feed Item Visibility
- Feed items that @mention the user if the user can access the feed item’s parent
- Feed items that @mention groups the user is a member of
- Record field changes on records whose parent is a record the user can see, including User, Group, and File records
- Feed items posted to the user
- Feed items posted to groups the user owns or is a member of
- Feed items for standard and custom records, for example, tasks, events, leads, accounts, files, and so on
Feed Types
1/chatter/feeds/news/userId
2/chatter/feeds/topics/topicId1ConnectApi.FeedItemPage newsFeedItemPage =
2 ConnectApi.ChatterFeeds.getFeedItemsFromFeed(null,
3 ConnectApi.FeedType.News, 'me');
4
5ConnectApi.FeedItemPage topicsFeedItemPage =
6 ConnectApi.ChatterFeeds.getFeedItemsFromFeed(null,
7 ConnectApi.FeedType.Topics, '0TOD00000000dUg');To get a filter feed, call ConnectApi.ChatterFeeds.getFeedItemsFromFilterFeed. To get a favorites feed, call ConnectApi.ChatterFavorites.getFeedItems.
- Bookmarks—Contains all feed items saved as bookmarks by the logged-in user.
- Company—Contains all feed items except feed items of type TrackedChange. To see the feed item, the user must have sharing access to its parent.
- Files—Contains all feed items that contain files posted by people or groups that the logged-in user follows.
- Filter—Contains the news feed filtered to contain feed items whose parent is a specified object type.
- Groups—Contains all feed items from all groups the logged-in user either owns or is a member of.
- Moderation—Contains all feed items that have been flagged for moderation. The Communities Moderation feed is available only to users with “Moderate Community Feeds” permissions.
- News—Contains all updates for people the logged-in user follows, groups the user is a member of, files and records the user is following, all updates for records whose parent is the logged-in user, and every feed item and comment that mentions the logged-in user or that mentions a group the logged-in user is a member of.
- People—Contains all feed items posted by all people the logged-in user follows.
- Record—Contains all feed items whose parent is a specified record, which could be a group, user, object, file, or any other standard or custom object. When the record is a group, the feed also contains feed items that mention the group.
- To—Contains all feed items with mentions of the logged-in user, feed items the logged-in user commented on, and feed items created by the logged-in user that are commented on.
- Topics—Contains all feed items that include the specified topic.
- UserProfile—Contains feed items created when a user changes records that can be tracked in a feed, feed items whose parent is the user, and feed items that @mention the user. This feed is different than the news feed, which returns more feed items, including group updates.
- Favorites—Contains favorites saved by the logged-in user. Favorites are feed searches, list views, and topics.
- Filter—Contains the news feed filtered to contain items whose parent is a specified entity type.
Posting a Feed Item
| Feed Type | Chatter REST API Resource | Chatter in Apex Method |
|---|---|---|
| News Feed | POST /chatter/feeds/news/userId/feed-items userId must be the ID of the logged-in user or the alias me. |
ConnectApi.ChatterFeeds.postFeedItem(communityIdOrNull, ConnectApi.FeedType.News, userId) userId must be the ID of the logged-in user or the alias me. |
| Record Feed | POST /chatter/feeds/record/recordId/feed-items | ConnectApi.ChatterFeeds.postFeedItem(communityIdOrNull, ConnectApi.FeedType.Record, recordId) |
| User Profile Feed | POST /chatter/feeds/user-profile/userId/feed-items | ConnectApi.ChatterFeeds.postFeedItem(communityIdOrNull, ConnectApi.FeedType.UserProfile, userId) |
When you post a feed item, you’re creating a child of a standard or custom object. For Chatter REST API, specify the parent object in the userId or recordId section of the resource. For Chatter in Apex, specify the parent object in the in the userId or recordId argument.
The parent property of the posted feed item contains information about the parent object.
- Post to yourself
- Make a POST request to the news feed, the record feed, or the user profile feed.
- For userId, specify the user ID of the logged-in user or the alias me.
- The parent property of the newly posted feed item contains the User Summary object (ConnectApi.UserSummary) of the logged-in user.
- Post to another user
- Make a POST request to the record feed or the user profile feed.
- For recordId or userId, specify the user ID of the target user.
- The parent property of the newly posted feed item contains the User Summary object (ConnectApi.UserSummary) of the target user.
- Post to a group
- Make a POST request to the record feed.
- For recordId, specify the group ID.
- The parent property of the newly posted feed item contains the Group object (ConnectApi.ChatterGroupSummary) of the specified group.
- Post to a record (such as a file or an account)
- Make a POST request to the record feed.
- For recordId, specify the record ID.
- The parent property of the new feed item depends on the record type specified in recordId. If the record type is File, the parent is the File Summary object (ConnectApi.FileSummary). If the record type is Group, the parent is a Group object (ConnectApi.ChatterGroupSummary). If the record type is User, the parent is a User Summary object (ConnectApi.UserSummary). For all other record types, the parent is a Record Summary object (ConnectApi.RecordSummary).
Getting Feed Items from a Feed
Getting feed items from a feed is similar, but not identical, for each feed type.
| Feed Type | Chatter REST API Resource | Chatter in Apex Method |
|---|---|---|
| Company | GET /chatter/feeds/company/feed-items | ConnectApi.ChatterFeeds.getFeedItemsFromFeed(communityIdOrNull, ConnectApi.FeedType.Company) |
| Moderation | GET /connect/communities/communityId/chatter/feeds/moderation/feed-items | ConnectApi.ChatterFeeds.getFeedItemsFromFeed(communityIdOrNull, ConnectApi.FeedType.Moderation) |
| Feed Type | Chatter REST API Resource | Chatter in Apex Method |
|---|---|---|
| Favorites | GET /chatter/feeds/favorites/subjectId/favoriteId/feed-items | ConnectApi.ChatterFavorites.getFeedItems(communityIdOrNull, subjectId, favoriteId) |
| Filter | GET /chatter/feeds/filter/subjectId/keyPrefix/feed-items | ConnectApi.ChatterFeeds.getFeedItemsFromFilterFeed(communityIdOrNull, subjectId, keyPrefix) |
| Feed Type | Chatter REST API Resource | Chatter in Apex Method |
|---|---|---|
| Record | GET /chatter/feeds/record/recordId/feed-items | ConnectApi.ChatterFeeds.getFeedItemsFromFeed(communityIdOrNull, ConnectApi.FeedType.Record, recordId) |
| Feed Type | Chatter REST API Resource | Chatter in Apex Method |
|---|---|---|
| Bookmarks, Files, Groups, News, People, To, Topics, User Profile | GET /chatter/feeds/feedType/subjectId/feed-items For example: GET /chatter/feeds/news/me/feed-items |
ConnectApi.ChatterFeeds.getFeedItemsFromFeed(communityIdOrNull, feedType, subjectId) For example: ConnectApi.ChatterFeeds.getFeedItemsFromFeed(communityIdOrNull, ConnectApi.FeedType.News, 'me') |