フィード要素の編集
この例では、updateFeedElement(communityId, feedElementId, feedElement) をコールしてフィード要素を編集します。フィード要素の種類のうち、編集可能なのはフィード項目のみです。
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17String communityId = Network.getNetworkId();
18
19// Get the last feed item created by the current user.
20List<FeedItem> feedItems = [SELECT Id FROM FeedItem WHERE CreatedById = :UserInfo.getUserId() ORDER BY CreatedDate DESC];
21if (feedItems.isEmpty()) {
22 // Return null within anonymous apex.
23 return null;
24}
25String feedElementId = feedItems[0].id;
26
27ConnectApi.FeedEntityIsEditable isEditable = ConnectApi.ChatterFeeds.isFeedElementEditableByMe(communityId, feedElementId);
28
29if (isEditable.isEditableByMe == true){
30 ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
31 ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
32 ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
33
34 messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
35
36 textSegmentInput.text = 'This is my edited post.';
37 messageBodyInput.messageSegments.add(textSegmentInput);
38
39 feedItemInput.body = messageBodyInput;
40
41 ConnectApi.FeedElement editedFeedElement = ConnectApi.ChatterFeeds.updateFeedElement(communityId, feedElementId, feedItemInput);
42}