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 ChaleCommented 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;– LeisureCommented Nov 5, 2013 at 3:47
Add a comment
|
1 Answer
//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!– LeisureCommented 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 Commented Nov 4, 2013 at 10:56