Quantcast
Channel: Active questions tagged feeditem - Salesforce Stack Exchange
Viewing all articles
Browse latest Browse all 160

Change FeedItemPost CreatedById using ConnectApi

$
0
0

I want to post chatter items via Apex with a link attached and an @ mention. I've been able to figure out how to attach the link and @ mention through research.

The next step to finishing this is to change the CreatedById of the post - Instead of it saying MyName to FriendName, I want it to say AnotherUser to FriendName.

Doing this using the FeedItem object is relatively easy since you can change the CreatedById value but I'm having trouble figuring out how I can do that with the ConnectApi.

Here is my code so far :

ConnectApi.FeedType feedType = ConnectApi.FeedType.UserProfile;
ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
feedItemInput.subjectId = 'Friends Id'

ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();

messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

textSegmentInput.text = 'Congrats ';
messageBodyInput.messageSegments.add(textSegmentInput);
mentionSegmentInput.id = 'Friends Id';
messageBodyInput.messageSegments.add(mentionSegmentInput);

ConnectApi.LinkCapabilityInput linkInput = new ConnectApi.LinkCapabilityInput();
linkInput.url = 'www.helloworld.com';
linkInput.urlName = 'hello world';

ConnectApi.FeedElementCapabilitiesInput feedElementCapabilitiesInput = new ConnectApi.FeedElementCapabilitiesInput();
feedElementCapabilitiesInput.link = linkInput;

feedItemInput.capabilities = feedElementCapabilitiesInput;
feedItemInput.body = messageBodyInput;
ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);

Open to other approaches too


Viewing all articles
Browse latest Browse all 160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>