http://deferloader.blog.uhuru.co.jp/?p=2763
//投稿処理
private void doChatter(list<string> chatterMsgList){
// ChatterGroup名指定
// ChatterGroup取得
//CollaborationGroup objCollaborationGroup = [select Id ,Name from CollaborationGroup where Name =: groupName limit 1];
//string targetGroupId = objCollaborationGroup.Id;
string targetGroupId = this.getGroupId();
string message ='';
for (String chatterMsg: chatterMsgList) {
message += chatterMsg;
}
// フィードのINSERT
FeedItem feed = new FeedItem();
feed.parentId = targetGroupId;
feed.body = message;
insert feed;
}
public static void toChatter(String chatterMsg) {
String communityId = null;
ConnectApi.FeedType feedType = ConnectApi.FeedType.UserProfile;
String userToMention = UserInfo.getUserId();
String subjectId = userToMention;
ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
// メンション
ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();
mentionSegment.id = userToMention;
messageInput.messageSegments.add(mentionSegment);
// 本文
ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = '\r\n';
messageInput.messageSegments.add(textSegment);
textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = chatterMsg;
messageInput.messageSegments.add(textSegment);
ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
input.body = messageInput;
// Chatter通知
ConnectApi.FeedItem feedItemRep =
ConnectApi.ChatterFeeds.postFeedItem(communityId, feedType, subjectId, input, null);
}