Activity Forums Salesforce® Discussions How can I add @mention when creating a FeedItem via APEX?

  • Ajit

    Member
    April 30, 2016 at 6:23 pm

    String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();

    String url = salesforceHost + '/services/data/v23.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('{ "body" : { "messageSegments" : [ { "type": "mention", "id" : "' + UserId + '" }, { "type": "text", "text" : "' + ' ' + chatterAlert + '" } ] } }');
    Http http = new Http();

    HTTPResponse res = http.send(req);

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos