I have a class that uses ConnectApi.ChatterFeeds.getFeedElementsFromFeed and from the result page I extract the mentioned users.

This is working as intended but now I have to create a test for this and I can't figure out how to prepare a FeedElementPage containing a FeedItem that has a body with a mention.

Here is what I have

        ConnectApi.FeedItem feedItem = new ConnectApi.FeedItem(); 
        ConnectApi.FeedBody body = new ConnectApi.FeedBody();  
        body.messageSegments = new List<ConnectApi.MessageSegment>();
        ConnectApi.TextSegment text1 = new ConnectApi.TextSegment();
        text1.text = 'Hi {';
        ConnectApi.MentionSegment mention = new ConnectApi.MentionSegment();
        mention.name = bob.FirstName + ' ' + bob.LastName;
        //mention.record = ; <======  no idea how to setup

        ConnectApi.TextSegment text2 = new ConnectApi.TextSegment();
        text1.text = '}, have you finished testing?';
        ((ConnectApi.FeedElement) feedItem).body = body;

I cannot find a way to populate the record which is a ConnectApi.ActorWithId object.


I found that you can retrieve your actor using ConnectApi.ChatterUsers.getUser(communityId, userId) so with that I can set the record reference like so:

mention.record = (ConnectApi.ActorWithId) chatterUser;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.