ChatterFavorites Class
Namespace
Usage
Use Connect in Apex to get and delete topics, list views, and feed searches that have been added as favorites. Add topics and feed searches as favorites, and update the last view date of a feed search or list view feed to the current system time.
In this image of Salesforce, “Build Issues” is a topic, “All Accounts” is a list view, and “United” is a feed search.

ChatterFavorites Methods
All methods in this class require Chatter and are subject to the per user, per namespace, per hour rate limit.
addFavorite(communityId, subjectId, searchText)
API Version
28.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedFavorite addFavorite(String communityId, String subjectId, String searchText)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- searchText
- Type: String
- Specify the text of the search to be saved as a favorite. This method can only create a feed search favorite, not a list view favorite or a topic.
Return Value
Type: ConnectApi.FeedFavorite
addRecordFavorite(communityId, subjectId, targetId)
API Version
28.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedFavorite addRecordFavorite(String communityId, String subjectId, String targetId)
Parameters
Return Value
Type: ConnectApi.FeedFavorite
deleteFavorite(communityId, subjectId, favoriteId)
API Version
28.0
Requires Chatter
Yes
Signature
public static Void deleteFavorite(String communityId, String subjectId, String favoriteId)
Parameters
Return Value
Type: Void
getFavorite(communityId, subjectId, favoriteId)
API Version
28.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedFavorite getFavorite(String communityId, String subjectId, String favoriteId)
Parameters
Return Value
Type: ConnectApi.FeedFavorite
getFavorites(communityId, subjectId)
API Version
28.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedFavorites getFavorites(String communityId, String subjectId)
Parameters
Return Value
Type: ConnectApi.FeedFavorites
getFeedElements(communityId, subjectId, favoriteId)
API Version
31.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedElementPage getFeedElements(String communityId, String subjectId, String favoriteId)
Parameters
Return Value
Usage
To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.
getFeedElements(communityId, subjectId, favoriteId, pageParam, pageSize, sortParam)
API Version
31.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedElementPage getFeedElements(String communityId, String subjectId, String favoriteId, String pageParam, Integer pageSize, ConnectApi.FeedSortOrder sortParam)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- pageParam
- Type: String
- Page token to use to view the page. Page tokens are returned as part of the response class, for example, currentPageToken or nextPageToken. If you pass in null, the first page is returned.
- pageSize
- Type: Integer
- Specifies the number of feed elements per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
- sortParam
- Type: ConnectApi.FeedSortOrder
- Values are:
- CreatedDateAsc—Sorts by oldest creation date. This sort order is available only for DirectMessageModeration, Draft, Isolated, Moderation, and PendingReview feeds.
- CreatedDateDesc—Sorts by most recent creation date.
- LastModifiedDateDesc—Sorts by most recent activity.
- MostViewed—Sorts by most viewed content. This sort order is available only for Home feeds when the ConnectApi.FeedFilter is UnansweredQuestions.
- Relevance—Sorts by most relevant content. This sort order is available only for Company, Home, and Topics feeds.
Return Value
Usage
To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.
getFeedElements(communityId, subjectId, favoriteId, recentCommentCount, elementsPerBundle, pageParam, pageSize, sortParam)
API Version
31.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedElementPage getFeedElements(String communityId, String subjectId, String favoriteId, Integer recentCommentCount, Integer elementsPerBundle, String pageParam, Integer pageSize, ConnectApi.FeedSortOrder sortParam)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- recentCommentCount
- Type: Integer
- Maximum number of comments to return with each feed element. The default value is 3.
- elementsPerBundle
- Type: Integer
- Maximum number of feed elements to include in a bundle. The value must be an integer between 0 and 10. The default value is 3.
- pageParam
- Type: String
- Page token to use to view the page. Page tokens are returned as part of the response class, for example, currentPageToken or nextPageToken. If you pass in null, the first page is returned.
- pageSize
- Type: Integer
- Specifies the number of feed elements per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
- sortParam
- Type: ConnectApi.FeedSortOrder
- Values are:
- CreatedDateAsc—Sorts by oldest creation date. This sort order is available only for DirectMessageModeration, Draft, Isolated, Moderation, and PendingReview feeds.
- CreatedDateDesc—Sorts by most recent creation date.
- LastModifiedDateDesc—Sorts by most recent activity.
- MostViewed—Sorts by most viewed content. This sort order is available only for Home feeds when the ConnectApi.FeedFilter is UnansweredQuestions.
- Relevance—Sorts by most relevant content. This sort order is available only for Company, Home, and Topics feeds.
Return Value
Usage
To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.
updateFavorite(communityId, subjectId, favoriteId, updateLastViewDate)
API Version
28.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedFavorite updateFavorite(String communityId, String subjectId, String favoriteId, Boolean updateLastViewDate)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- updateLastViewDate
- Type: Boolean
- Specify whether to update the last view date of the specified favorite to the current system time (true) or not (false).
Return Value
Type: ConnectApi.FeedFavorite
ChatterFavorites Test Methods
For information about using these methods to test your ConnectApi code, see Testing ConnectApi Code.
setTestGetFeedElements(communityId, subjectId, favoriteId, result)
API Version
31.0
Signature
public static Void setTestGetFeedElements(String communityId, String subjectId, String favoriteId, ConnectApi.FeedElementPage result)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- result
- Type: ConnectApi.FeedElementPage
- Object containing test data.
Return Value
Type: Void
setTestGetFeedElements(communityId, subjectId, favoriteId, pageParam, pageSize, sortParam, result)
API Version
31.0
Signature
public static Void setTestGetFeedElements(String communityId, String subjectId, String favoriteId, String pageParam, Integer pageSize, ConnectApi.FeedSortOrder sortParam, ConnectApi.FeedElementPage result)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- pageParam
- Type: String
- Page token to use to view the page. Page tokens are returned as part of the response class, for example, currentPageToken or nextPageToken. If you pass in null, the first page is returned.
- pageSize
- Type: Integer
- Specifies the number of feed elements per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
- sortParam
- Type: ConnectApi.FeedSortOrder
- Values are:
- CreatedDateAsc—Sorts by oldest creation date. This sort order is available only for DirectMessageModeration, Draft, Isolated, Moderation, and PendingReview feeds.
- CreatedDateDesc—Sorts by most recent creation date.
- LastModifiedDateDesc—Sorts by most recent activity.
- MostViewed—Sorts by most viewed content. This sort order is available only for Home feeds when the ConnectApi.FeedFilter is UnansweredQuestions.
- Relevance—Sorts by most relevant content. This sort order is available only for Company, Home, and Topics feeds.
- result
- Type: ConnectApi.FeedElementPage
- Object containing test data.
Return Value
Type: Void
setTestGetFeedElements(communityId, subjectId, favoriteId, recentCommentCount, elementsPerBundle, pageParam, pageSize, sortParam, result)
API Version
31.0
Signature
public static Void setTestGetFeedElements(String communityId, String subjectId, String favoriteId, Integer recentCommentCount, Integer elementsPerBundle, String pageParam, Integer pageSize, ConnectApi.FeedSortOrder sortParam, ConnectApi.FeedElementPage result)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- recentCommentCount
- Type: Integer
- Maximum number of comments to return with each feed element. The default value is 3.
- elementsPerBundle
- Type: Integer
- Maximum number of feed elements to include in a bundle. The value must be an integer between 0 and 10. The default value is 3.
- pageParam
- Type: String
- Page token to use to view the page. Page tokens are returned as part of the response class, for example, currentPageToken or nextPageToken. If you pass in null, the first page is returned.
- pageSize
- Type: Integer
- Specifies the number of feed elements per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
- sortParam
- Type: ConnectApi.FeedSortOrder
- Values are:
- CreatedDateAsc—Sorts by oldest creation date. This sort order is available only for DirectMessageModeration, Draft, Isolated, Moderation, and PendingReview feeds.
- CreatedDateDesc—Sorts by most recent creation date.
- LastModifiedDateDesc—Sorts by most recent activity.
- MostViewed—Sorts by most viewed content. This sort order is available only for Home feeds when the ConnectApi.FeedFilter is UnansweredQuestions.
- Relevance—Sorts by most relevant content. This sort order is available only for Company, Home, and Topics feeds.
- result
- Type: ConnectApi.FeedElementPage
- Object containing test data.
Return Value
Type: Void
Retired ChatterFavorites Methods
getFeedItems(communityId, subjectId, favoriteId)
API Version
28.0–31.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedItemPage getFeedItems(String communityId, String subjectId, String favoriteId)
Parameters
Return Value
Type: ConnectApi.FeedItemPage
Usage
To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.
getFeedItems(communityId, subjectId, favoriteId, pageParam, pageSize, sortParam)
API Version
28.0–31.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedItemPage getFeedItems(String communityId, String subjectId, String favoriteId, String pageParam, Integer pageSize, ConnectApi.FeedSortOrder sortParam)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- pageParam
- Type: String
- Page token to use to view the page. Page tokens are returned as part of the response class, for example, currentPageToken or nextPageToken. If you pass in null, the first page is returned.
- pageSize
- Type: Integer
- Number of feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
- sortParam
- Type: ConnectApi.FeedSortOrder
- Values are:
- CreatedDateAsc—Sorts by oldest creation date. This sort order is available only for DirectMessageModeration, Draft, Isolated, Moderation, and PendingReview feeds.
- CreatedDateDesc—Sorts by most recent creation date.
- LastModifiedDateDesc—Sorts by most recent activity.
- MostViewed—Sorts by most viewed content. This sort order is available only for Home feeds when the ConnectApi.FeedFilter is UnansweredQuestions.
- Relevance—Sorts by most relevant content. This sort order is available only for Company, Home, and Topics feeds.
Return Value
Type: ConnectApi.FeedItemPage
Usage
To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.
getFeedItems(communityId, subjectId, favoriteId, recentCommentCount, pageParam, pageSize, sortParam)
API Version
29.0–31.0
Requires Chatter
Yes
Signature
public static ConnectApi.FeedItemPage getFeedItems(String communityId, String subjectId, String favoriteId, Integer recentCommentCount, String pageParam, Integer pageSize, FeedSortOrder sortParam)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- recentCommentCount
- Type: Integer
- Maximum number of comments to return with each feed item. The default value is 3.
- pageParam
- Type: String
- Page token to use to view the page. Page tokens are returned as part of the response class, for example, currentPageToken or nextPageToken. If you pass in null, the first page is returned.
- pageSize
- Type: Integer
- Number of feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
- sortParam
- Type: ConnectApi.FeedSortOrder
- Values are:
- CreatedDateAsc—Sorts by oldest creation date. This sort order is available only for DirectMessageModeration, Draft, Isolated, Moderation, and PendingReview feeds.
- CreatedDateDesc—Sorts by most recent creation date.
- LastModifiedDateDesc—Sorts by most recent activity.
- MostViewed—Sorts by most viewed content. This sort order is available only for Home feeds when the ConnectApi.FeedFilter is UnansweredQuestions.
- Relevance—Sorts by most relevant content. This sort order is available only for Company, Home, and Topics feeds.
Return Value
Type: ConnectApi.FeedItemPage
Usage
To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.
setTestGetFeedItems(communityId, subjectId, favoriteId, result)
API Version
28.0–31.0
Signature
public static Void setTestGetFeedItems(String communityId, String subjectId, String favoriteId, ConnectApi.FeedItemPage result)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- result
- Type: ConnectApi.FeedItemPage
- Object containing test data.
Return Value
Type: Void
setTestGetFeedItems(communityId, subjectId, favoriteId, pageParam, pageSize, sortParam, result)
API Version
28.0–31.0
Signature
public static Void setTestGetFeedItems(String communityId, String subjectId, String favoriteId, String pageParam, Integer pageSize, FeedSortOrder sortParam, ConnectApi.FeedItemPage result)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- pageParam
- Type: String
- Page token to use to view the page. Page tokens are returned as part of the response class, for example, currentPageToken or nextPageToken. If you pass in null, the first page is returned.
- pageSize
- Type: Integer
- Number of feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
- sortParam
- Type: ConnectApi.FeedSortOrder
- Values are:
- CreatedDateAsc—Sorts by oldest creation date. This sort order is available only for DirectMessageModeration, Draft, Isolated, Moderation, and PendingReview feeds.
- CreatedDateDesc—Sorts by most recent creation date.
- LastModifiedDateDesc—Sorts by most recent activity.
- MostViewed—Sorts by most viewed content. This sort order is available only for Home feeds when the ConnectApi.FeedFilter is UnansweredQuestions.
- Relevance—Sorts by most relevant content. This sort order is available only for Company, Home, and Topics feeds.
- result
- Type: ConnectApi.FeedItemPage
- Object containing test data.
Return Value
Type: Void
setTestGetFeedItems(communityId, subjectId, favoriteId, recentCommentCount, pageParam, pageSize, sortParam, result)
API Version
29.0–31.0
Signature
public static Void setTestGetFeedItems(String communityId, String subjectId, String favoriteId, Integer recentCommentCount, String pageParam, Integer pageSize, FeedSortOrder sortParam, ConnectApi.FeedItemPage result)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- subjectId
- Type: String
- ID of the context user or the alias me.
- favoriteId
- Type: String
- ID of a favorite.
- recentCommentCount
- Type: Integer
- Maximum number of comments to return with each feed item. The default value is 3.
- pageParam
- Type: String
- Page token to use to view the page. Page tokens are returned as part of the response class, for example, currentPageToken or nextPageToken. If you pass in null, the first page is returned.
- pageSize
- Type: Integer
- Number of feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
- sortParam
- Type: ConnectApi.FeedSortOrder
- Values are:
- CreatedDateAsc—Sorts by oldest creation date. This sort order is available only for DirectMessageModeration, Draft, Isolated, Moderation, and PendingReview feeds.
- CreatedDateDesc—Sorts by most recent creation date.
- LastModifiedDateDesc—Sorts by most recent activity.
- MostViewed—Sorts by most viewed content. This sort order is available only for Home feeds when the ConnectApi.FeedFilter is UnansweredQuestions.
- Relevance—Sorts by most relevant content. This sort order is available only for Company, Home, and Topics feeds.
- result
- Type: ConnectApi.FeedItemPage
- Object containing test data.
Return Value
Type: Void