You need to sign in to do that
Don't have an account?
Michael M
Add createdbyid to chatter apex post
Hello, I need to set the createdbyid of a chatter post being made from apex. How do I do so?
Contact c = [ Select id, related_referral__r.ownerid, related_referral__r.name From Contact Where Id =: contactRecordId];
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>();
mentionSegmentInput.id = c.related_referral__r.ownerid;
messageBodyInput.messageSegments.add(mentionSegmentInput);
textSegmentInput.text = ' This contact, the next of kin of patient "' + c.related_referral__r.name +'", has responded to your text and shown interest. Please follow up with them as soon as you cannnnnnnn.';
messageBodyInput.messageSegments.add(textSegmentInput);
feedItemInput.body = messageBodyInput;
feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
feedItemInput.subjectId = c.Id;
ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);
Contact c = [ Select id, related_referral__r.ownerid, related_referral__r.name From Contact Where Id =: contactRecordId];
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>();
mentionSegmentInput.id = c.related_referral__r.ownerid;
messageBodyInput.messageSegments.add(mentionSegmentInput);
textSegmentInput.text = ' This contact, the next of kin of patient "' + c.related_referral__r.name +'", has responded to your text and shown interest. Please follow up with them as soon as you cannnnnnnn.';
messageBodyInput.messageSegments.add(textSegmentInput);
feedItemInput.body = messageBodyInput;
feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
feedItemInput.subjectId = c.Id;
ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);
ConnectApi might not support createdbyid in chatter post.
Review below links.
https://developer.salesforce.com/forums/?id=906F00000009AEhIAM
https://salesforce.stackexchange.com/questions/102654/trying-to-post-a-chatter-feed-item-with-mention-and-as-someone-else
Thanks,
Vinay Kumar
All Answers
Sadly using Connect api you can only post feed items as the current logged-in user.
Check this for reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_differences.htm
Hope you find another way to achieve your requirement.
You can try but I dont see it working.
Good luck and if it helped you please mark as correct so the question is solved
ConnectApi might not support createdbyid in chatter post.
Review below links.
https://developer.salesforce.com/forums/?id=906F00000009AEhIAM
https://salesforce.stackexchange.com/questions/102654/trying-to-post-a-chatter-feed-item-with-mention-and-as-someone-else
Thanks,
Vinay Kumar