I want to add a hyperlink to the body of a feeditem with apex code. I tried to with class of EncodingUtil.urlEncode but it is not work. So I`d like to know how shall I do. Thx!

  • Welcome to SFSE, Leisure. Can you share what code you tried and what the result was?
    – Mike Chale
    Nov 1, 2013 at 12:36
  • Yes, follows are: String sUrlRewrite = System.URL.getSalesforceBaseUrl().toExternalForm(); newItem = new FeedItem(); newItem.ParentId = targetAccountId; newItem.Type = 'LinkPost'; newItem.Body = 'Case subject: ' + c.Subject + '\n Account Name: ' + map_accountId_account.get(c.AccountId).Name; newItem.Title = c.Subject; newItem.LinkUrl = sUrlRewrite + '/' + c.Id;
    – Leisure
    Nov 5, 2013 at 3:47

1 Answer 1

      //Adding a Link post
               FeedItem post = new FeedItem();
               post.ParentId = oId; //eg. Opportunity id, custom object id..
               post.Body = 'Enter post text here';
               post.LinkUrl = 'http://www.someurl.com';
               insert post;


You can refer a field named "type" in Feeditem that decides the body.You have following choices

The type of FeedItem you can use is LinkPost—a URL posting on a feed

  • Thanks for your answer. My mate also had told me about this parameter, it is ok. Your are right!
    – Leisure
    Nov 4, 2013 at 10:44
  • If the answer answers your question its helpful if you mark it ticked and also upvote .Marking it as answer helps others while surfing Nov 4, 2013 at 10:56

You must log in to answer this question.

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