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.
String communityId = Network.getNetworkId(); // Get the last feed item created by the context user. List<FeedItem> feedItems = [SELECT Id FROM FeedItem WHERE CreatedById = :UserInfo.getUserId() WITH USER_MODE ORDER BY CreatedDate DESC]; if (feedItems.isEmpty()) { // Return null within anonymous apex. return null; } String feedElementId = feedItems[0].id; ConnectApi.FeedEntityIsEditable isEditable = ConnectApi.ChatterFeeds.isFeedElementEditableByMe(communityId, feedElementId); if (isEditable.isEditableByMe == true){ ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput(); ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput(); ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput(); messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>(); textSegmentInput.text = 'This is my edited post.'; messageBodyInput.messageSegments.add(textSegmentInput); feedItemInput.body = messageBodyInput; ConnectApi.FeedElement editedFeedElement = ConnectApi.ChatterFeeds.updateFeedElement(communityId, feedElementId, feedItemInput); }