how can i bring out something similar to " < a href="Https://www.google.com">Search


in the following code.

 trigger chatterfeed on Feedback__c (after update) {
   for(Feedback__c feed:trigger.old){
       FeedItem post = new FeedItem();
       post.ParentId = 'Some id';
       String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm()+'/'+ Feed.id;
      String stringURL  = '<a href='+fullFileURL+' >Test</a>/>';
      post.Body =stringURL;
      insert post;

for which i get a post with a link like below and clicking on it should direct to me to the link on the href. " Test " 'String stringURL = 'Test/>'; this does no work..

The post.LinkUrl will just post the url... my intention is not to post a link. my intention is to get a hyperlink in the post body. so that when i click on the hyper link it redirects me to the link given in href link.

String stringURL = 'Test/>';

by hyper link i mean : Test by link i mean :URL.getSalesforceBaseUrl().toExternalForm()+ ' / ' + Feed.id;


Like in the above html code if i click on Search , it will take me to google.com... Some thing like this.

2 Answers 2


You will need use LinkURL field of the FeedItem,Please find the sample code

 //Adding a Link post
        FeedItem lnkpost = new FeedItem();
        lnkpost.ParentId = feed.Id; //eg. Opportunity id, custom object id..
        lnkpost.Body = 'Test';
        lnkpost.LinkUrl = fullFileURL ;
        insert lnkpost;
  • Thank you so much. this was not what i exactly wanted. but it did help in some way...
    – Anton
    Commented Aug 13, 2014 at 13:48
  • 1
    Any idea if LinkURL can be masked as a Text that has a background URL to take the user to the actual link URL ? [UPDATE] Sorry found the answer - Title field on FeedItem was the one when Type is LinkPost !
    – peevesy
    Commented Oct 27, 2021 at 4:17

As Mohith said, you need to use 'LinkUrl'. Also, your trigger was not bulkified - you have a DML statement inside a for loop, that's a sure way to hit governor limits.

Try this:

trigger chatterfeed on Feedback__c (after update) {

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

    for (Feedback__c feed : trigger.old) { 

        String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm()+'/'+ Feed.id; 

        FeedItem post = new FeedItem(
            ParentId = 'Some id',
            Body = 'Something',
            LinkUrl = fullFileURL;



    if (!feedItemsToInsert.isEmpty()) {

        try {

            insert feedItemsToInsert;

        } catch (Exception ex) {

            // do something about DML failure.

  • I know the trigger is not perfect. it was just a sample to show what i actually wanted...
    – Anton
    Commented Aug 13, 2014 at 13:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .