I have a trigger that posts to a Project Object's feed and @mentions someone. The only problem is that I need to be able to post the message as another user, not the user who is logged in. How can I do this? Here is my trigger.
trigger autoProjectChatter on Milestone1_Project__c ( after update) {
for(Milestone1_Project__c project : Trigger.New) {
if (project.Project_stage__c == 'Ready to Deliver') {
string what = project.Id;
string name = 'Album';
String communityId = null;
ConnectApi.FeedType feedType = ConnectApi.FeedType.Record;
ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
ConnectApi.TextSegmentInput textSegment;
ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();
messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
mentionSegment.id = '005j0000000Y3tO';
messageInput.messageSegments.add(mentionSegment);
textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = ' Brenda, I am pleased to announce that we have completed the project under budget, and well within our proposed timeline!';
messageInput.messageSegments.add(textSegment);
input.body = messageInput;
//input.subjectId = t.whatID;
ConnectApi.FeedItem feedItemRep = ConnectApi.ChatterFeeds.postFeedItem(communityId, feedType, what, input, null);
}
}
}