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
KaminiKamini 

Create Hyper links in Chatter Message

Hi,

 

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.

 

Thanks,

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 = 'https://ap1.salesforce.com/0039000000LDeAV';
        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.setMethod('POST');
        req.setEndpoint(url);
        req.setHeader('Content-type', 'application/json');
        req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());            
        req.setBody('{ "attachment":{ "attachmentType":"Link","url": "http://www.salesforce.com","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);
    }
}