Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

Edit a Feed Element

Call a method to edit a feed element.
Call updateFeedElement(communityId, feedElementId, feedElement) to edit a feed element. Feed items are the only type of feed element that can be edited.
1String communityId = Network.getNetworkId();
2
3// Get the last feed item created by the context user.
4List<FeedItem> feedItems = [SELECT Id FROM FeedItem WHERE CreatedById = :UserInfo.getUserId() ORDER BY CreatedDate DESC];
5if (feedItems.isEmpty()) {
6    // Return null within anonymous apex.
7    return null;
8}
9String feedElementId = feedItems[0].id;
10
11ConnectApi.FeedEntityIsEditable isEditable = ConnectApi.ChatterFeeds.isFeedElementEditableByMe(communityId, feedElementId);
12
13if (isEditable.isEditableByMe == true){
14    ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
15    ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
16    ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
17
18    messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
19
20    textSegmentInput.text = 'This is my edited post.';
21    messageBodyInput.messageSegments.add(textSegmentInput);
22
23    feedItemInput.body = messageBodyInput;
24
25    ConnectApi.FeedElement editedFeedElement = ConnectApi.ChatterFeeds.updateFeedElement(communityId, feedElementId, feedItemInput);
26}