function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ricardo Palma 16Ricardo Palma 16 

How convert an Account name to a hyperlink in a chatter post using ConnectApi in Apex.

I'm creating a chatter feed using ConnectApi.
I'm posting some text but also I need to create a link to the Account record, baically is the account name is ABC Company I want the user to be able to click the name to go to the Account record. Currently I have the url to the but what I need is click on the account name.

Here is part of the code.
message =  'This Account has requested cancellation.  Please review and take action on ' + accMap.get(urec.AccountId).Name + ' ' + System.Url.getSalesforceBaseURL().toExternalForm() + '/' + accMap.get(urec.AccountId).Name ;



 ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
 ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
 ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
 ConnectApi.TextSegmentInput textSegmentInputLine = new ConnectApi.TextSegmentInput();
 messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
 textSegmentInput.text = message + twolines; 
messageBodyInput.messageSegments.add(textSegmentInput)  ;
feedItemInput.body = messageBodyInput ;
vinaykumar s 8vinaykumar s 8
Hi Ricardo,
 use ConnectApi.​LinkCapabilityInput  or ConnectApi.LinkSegmentInput Class to link ur account in chatter 

reffer this link
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_input_link_capability.htm

Regards,
vinaykumar s
 
Raj VakatiRaj Vakati
try this pls
 
message =  'This Account has requested cancellation.  Please review and take action on ' + accMap.get(urec.AccountId).Name + ' ' + System.Url.getSalesforceBaseURL().toExternalForm() + '/' + accMap.get(urec.AccountId).Name ;



 ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
 ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
 ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
 ConnectApi.TextSegmentInput textSegmentInputLine = new ConnectApi.TextSegmentInput();
 messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
 textSegmentInput.text = message + twolines; 
messageBodyInput.messageSegments.add(textSegmentInput)  ;


// The FeedElementCapabilitiesInput object holds the capabilities of the feed item.
// For this feed item, we define a link capability.

ConnectApi.LinkCapabilityInput linkInput = new ConnectApi.LinkCapabilityInput();
linkInput.url = 'https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_input_link_capability.htm';
linkInput.urlName = '/'+accMap.get(urec.AccountId).Name ;

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

feedItemInput.capabilities = feedElementCapabilitiesInput;

// Post the feed item. 
ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);