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

Create Hyper links in Chatter Message



Is there any way to add hyperLink to a record in Chatter Meassge using Apex Code. Suppose following is the chatter message:


Work has been accepted and assigned to Contact.


In the above message the Coantct is the hyperlink to the contact record. Please help me for creating the hyperLink to contact record.



Bindhyachal Kumar SinghBindhyachal Kumar Singh

Hi Kamini,


I think currently only two parameters is provided by salesforce for chatter Rest API messagesegments links.


If we have also URLName parameters available in salesforce then we can do this.


Currently it is not possible for us to make a hyperlink with URLNAME instead of url in Feeditem body.


Message Segment Input: Link


type String Value is Link 23.0 url URL URL to be used for the link 23.0


public class ChatterTest{
    public void chatterRestAPI(){
        String RecordId = giverecordid;
        String Urllink = '';
        String chatterAlert = 'This is test of Chatter API';
        String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();        
        String url =  salesforceHost + '/services/data/v27.0/chatter/feeds/record/' + RecordId + '/feed-items';            
        HttpRequest req = new HttpRequest();
        req.setHeader('Content-type', 'application/json');
        req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());            
        req.setBody('{ "attachment":{ "attachmentType":"Link","url": "","urlName": "Salesforce" }}');
        req.setBody('{ "body" : { "messageSegments" : [ { "type": "link", "url" : "' + urllink+ '" }, { "type": "text",  "text" : "' + ' ' + chatterAlert +  '" } ] } }');
        Http http = new Http();      
        HTTPResponse res = http.send(req);
        System.debug('Response is' +res);