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 Question Title and Post
Call a method to edit a question title and post.
Call updateFeedElement(communityId,
feedElementId, feedElement) to edit a question title and post.
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
15 ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
16 ConnectApi.FeedElementCapabilitiesInput feedElementCapabilitiesInput = new ConnectApi.FeedElementCapabilitiesInput();
17 ConnectApi.QuestionAndAnswersCapabilityInput questionAndAnswersCapabilityInput = new ConnectApi.QuestionAndAnswersCapabilityInput();
18 ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
19 ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
20
21 messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
22
23 textSegmentInput.text = 'This is my edited question.';
24 messageBodyInput.messageSegments.add(textSegmentInput);
25
26 feedItemInput.body = messageBodyInput;
27 feedItemInput.capabilities = feedElementCapabilitiesInput;
28
29 feedElementCapabilitiesInput.questionAndAnswers = questionAndAnswersCapabilityInput;
30 questionAndAnswersCapabilityInput.questionTitle = 'Where is my edited question?';
31
32 ConnectApi.FeedElement editedFeedElement = ConnectApi.ChatterFeeds.updateFeedElement(communityId, feedElementId, feedItemInput);
33}