I want to get only EmailMessageEvent feeds for a Case. I found two types of filtering criteria in : ConnectApi.ChatterFeeds.getFeedElementsFromFeed
- using ConnectApi.FeedType in getFeedElementsFromFeed(communityId, feedType, subjectId)
- using ConnectApi.FeedFilter in getFeedElementsFromFeed(communityId, feedType, subjectId, recentCommentCount, density, pageParam, pageSize, sortParam, filter)
References : Chatter Feed Class
Is there any way to filter by ConnectApi.FeedItemType
Regretfully, Chatter feeds cannot be directly filtered using ConnectApi.Use the getFeedElementsFromFeed function to feedItemType.
The ConnectApi.FeedType and ConnectApi.FeedFilter filters are intended for more general filtering criteria, including filtering by feed type (e.g., record feed, group feed), or by more focused filters, like "recent comments" or "my posts."
you can indirectly achieve the desired filtering by combining the following approaches:
- Retrieve All Feed Elements:
- Use getFeedElementsFromFeed to fetch all feed elements for a specific Case.
- Filter in Apex:
- Iterate through the retrieved feed elements and filter them based on their type attribute.
- Keep only the EmailMessageEvent feed items.
Here's a code example:
List<ConnectApi.FeedItem> feedItems = ConnectApi.ChatterFeeds.getFeedElementsFromFeed(null, ConnectApi.FeedType.Record, caseId);
List<ConnectApi.FeedItem> emailMessageEvents = new List<ConnectApi.FeedItem>();
for (ConnectApi.FeedItem item : feedItems) {
if (item.type == ConnectApi.FeedItemType.EmailMessageEvent) {
emailMessageEvents.add(item);
}
}
- Retrieve All Feed Elements: