2

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 '13 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 '13 at 3:47
4
      //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;

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_feeditem.htm

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 '13 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 – Mohith Shrivastava Nov 4 '13 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.