0% found this document useful (0 votes)
60 views1 page

Chatter Mention Post

The document contains code to retrieve a task record, loop through it and post a message to the task's related record feed mentioning the task owner and a hardcoded message. It retrieves the task, constructs the HTTP request to post to the feed endpoint, sets headers and body and sends the request to post the message.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views1 page

Chatter Mention Post

The document contains code to retrieve a task record, loop through it and post a message to the task's related record feed mentioning the task owner and a hardcoded message. It retrieves the task, constructs the HTTP request to post to the feed endpoint, sets headers and body and sends the request to post the message.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

List<Task> listTask = [select id, owner.

name, WhatId from task where id =


'00T9000002bd9m2EAA' and [Link] = 'Campaign'];

List<FeedItem> listFeedItem = new List<FeedItem>();

String salesforceHost = [Link]().toExternalForm();

for (Task tsk : listTask)


{
String url =
'[Link] + [Link]
+ '/feed-items';

HttpRequest req = new HttpRequest();

[Link]('POST');
[Link](url);
[Link]('Content-type', 'application/json');
[Link]('Authorization', 'OAuth ' + [Link]());
[Link]('{ "body" : { "messageSegments" : [ { "type": "mention", "id" : "'
+ [Link] + '" }, { "type": "text", "text" : "' + ' ' + 'hellow shoukat bhai'
+ '" } ] } }');

Http http = new Http();


HTTPResponse res = [Link](req);

You might also like