+ Start a Discussion
S N 27S N 27 

Multiple links in a single Chatter feed using Connect api

Hi All,
I have a requirement wherein I am required to have two separate links in a single chatter feed. I was able to successfully fit in a single link with the below code, but having more than one link seems to be a challenging task.
Please help me out accomodating multiple links. Thanks in advance.

This is a piece of code:


feedItemInput.body = messageBodyInput;              
                feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
                feedItemInput.subjectId = e.id;
               
               
                // add the attachment
                //ConnectApi.LinkAttachmentInput linkIn = new ConnectApi.LinkAttachmentInput();
                ConnectApi.LinkCapabilityInput linkIn = new ConnectApi.LinkCapabilityInput();
                linkIn.urlName = 'Mobile users click on the below link';              
                linkIn.url = URL.getSalesforceBaseUrl().toExternalForm()+'/apex/MyNotes?id='+e.id;
               //linkIn.urlName = 'Desktop users click on the below link';              
                //linkIn.url = URL.getSalesforceBaseUrl().toExternalForm()+'/'+e.id;
                feedElementCapabilitiesInput.link = linkIn;              
                feedItemInput.capabilities = feedElementCapabilitiesInput;
                feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
                ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(null,feedItemInput,null);
​​​
Nathan GreerNathan Greer
Hi Satish,

It's not going to be the answer you want to hear, but from my understanding, you can only add 1 link attachment to a post.

You can accomplish having 2 links on a post using the LinkSegmentInput class and constructing the post with multiple links/text segments/etc. However, these links will just show as inline links instead of the nice look that you get with a link attachment. If you decide to go this route, you probably want to look into the Connect API Helper Class (https://github.com/forcedotcom/ConnectApiHelper)

Thanks,
Nathan