1

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 {';
        body.messageSegments.add(text1);
        
        ConnectApi.MentionSegment mention = new ConnectApi.MentionSegment();
        mention.name = bob.FirstName + ' ' + bob.LastName;
        //mention.record = ; <======  no idea how to setup
        body.messageSegments.add(mention);

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

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

1 Answer 1

2

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;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .