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
ptorricdevelptorricdevel 

creating a post with mention via a javascript pushbutton

Hi all, i'm working on a Manual Request pushbutton that send a chatter post to some other user for alerting.

 

I succesfully create the code, something like this:

 


var msg='bla bla bla bla';

var cm=new sforce.SObject("FeedItem"); 
cm.ParentId='{!Opportunity.Id}'; 
cm.Body=msg; 


How can i introduce the mention for user that i need to alert?

Can i put it in msg string directly, like...

var msg='@user bla bla bla';

have to enclose in brakets?

 

thank you all

ptorricdevelptorricdevel

i found something in chatter rest api:

{ "body" :    { 
      "messageSegments" : [ 
         { 
           "type": "mention", 
           "id" : "005D0000001GpHp" 
         },
         { 
           "type": "text", 
           "text" : " Did you see the new plans?" 
         }
      ]
    }
}



it seems that the body can be composed by different part, but how can i do the same without chatter rest api?

 

ChrisOctagonChrisOctagon

Sorry but at this time I believe you can only make new feed items with @-mentions using the Chatter REST API.

kevinwukevinwu

Hi Chris,

 

Do you know if it's possible to add @mentions via Apex or AJAX yet? I know we can do this via the Chatter REST API but has Salesforce added this functionality in Apex/AJAX?

 

Thanks!!!

ChrisOctagonChrisOctagon

Not currently. One workaround you can use is to call into the Chatter REST API from Apex by using Apex's built-in HttpRequest object and JSON parser. I believe you can use the context user's session ID as your OAuth token.