Skip to content

Instantly share code, notes, and snippets.

@101dvlp
Last active August 1, 2017 10:29
Show Gist options
  • Save 101dvlp/238f2eb6ca166518d9ca1da184847577 to your computer and use it in GitHub Desktop.
Save 101dvlp/238f2eb6ca166518d9ca1da184847577 to your computer and use it in GitHub Desktop.
ChatterFeedFromApex
public pageReference feedWithMention(){
ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
// メンション先のユーザを指定
User u = [SELECT Id FROM User WHERE Name = 'testUser' LIMIT 1];
mentionSegmentInput.id = u.Id;
messageBodyInput.messageSegments.add(mentionSegmentInput);
// chatterフィードに選択した値を格納
textSegmentInput.text = '\r\n' + selected + 'を選択しました。';
messageBodyInput.messageSegments.add(textSegmentInput);
feedItemInput.body = messageBodyInput;
feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
// フィード先に取引先責任者を関連付ける
feedItemInput.subjectId = cont.Id;
ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);
// 元の取引先責任者詳細ページに戻す
PageReference pageRef = new PageReference('/' + cont.Id);
return pageRef;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment