+ Start a Discussion
sfdc dev 2264sfdc dev 2264 

Making chatter feed as hyperlink in apex

Hi 

i have ave a Alex class which posts the chatter messsge in case 


body+= ‘\ recovery no’+ (rec.name)

i want to make that as a hyperlink with recovery number so when I click on the link it should take me to respective recovery record 

help me how to achieve the same

thanks in advance 
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

Please refer to the below links which might help you further with the above requirement.

https://salesforce.stackexchange.com/questions/732/create-chatter-post-with-mix-of-hyperlinks-and-text-in-the-body-in-apex-code

https://developer.salesforce.com/forums/?id=906F00000009AD8IAM

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
sfdc dev 2264sfdc dev 2264
Hi I tried the above mentioned links but didn’t work
Raj VakatiRaj Vakati

Use ConnectApi.​LinkCapabilityInput  or ConnectApi.LinkSegmentInput Class to link ur url in chatter 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_input_link_capability.htm
 
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);