2

I have a requirement to add a link from one case to another within the case feed. This will happen from a future method called from trigger context, so it should be bulk safe. For this reason, I'd like to insert FeedItem records directly instead of using ConnectAPI.

I've tried a few things with partial success:

  • I tried to insert a FeedItem of type TextPost with IsRichText set to true, with an embedded <a> tag pointing to the url '/' + caseId. This gave an error that the link must begin with 'http:', 'https:', etc.
  • I changed the link to 'sfdc:' + caseId (the form required for img src attributes when using RichText), but got the same error.
  • I changed the link to a full SFDC url (URL.getSalesforceBaseUrl().toExternalForm() + '/' + caseId), which generated the error, "Context user does not have permission to create rich text in feed." I can find no documentation of this error, but I have seen claims that you can only insert a RichText TextItem via SOAP API.
  • I switched to creating a FeedItem of type LinkPost. Again, I had to use a full URL. This works, but the link opens in a new browser tab instead of within a new Console tab.

This last will work if no other choice, but I'd really prefer a way to show a link to the other case that would open the other case directly in the current Console. I don't particularly care what FeedItem type I use. Is this possible?

  • if you don't use richtext, and just emplace ` changed the link to a full SFDC url (URL.getSalesforceBaseUrl().toExternalForm() + '/' + caseId`, won't the browser detect this as a URL and implicitly make it clickable? – cropredy Sep 16 '19 at 16:21
  • my comment was garbled; try this: if you don't use richtext, and just change the link to a full SFDC url URL.getSalesforceBaseUrl().toExternalForm() + '/' + caseId, won't the browser detect this as a URL and implicitly make it clickable? – cropredy Sep 17 '19 at 0:24
  • @cropredy No but Yes... I think SF converted the inline URL, not the browser, but it worked, and even opened inside the console. Please add this as an answer so I can accept it. – Jason Clark Sep 17 '19 at 14:02
1

You could try the following

insert new FeedItem (
   Body = URL.getSalesforceBaseUrl().toExternalForm() + '/' + caseId,
   ParentId = someCaseId,
   Type = 'TextPost',
   Visibility = 'AllUsers');

In my situation, once inserted, I requeried via Workbench the FeedItem and

SELECT Body FROM FeedItem where id='0D51W00007HxBM6SAN'

and the value of Body remains as text (not HTML) in the database. But, the Lightning page that displayed the feed took the text and turned it into an HTML anchor tag

<a href="https://cropredy-dev-ed.my.salesforce.com/5001W00001GL09I" 
   title="" 
   data-value="https://cropredy-dev-ed.my.salesforce.com/5001W00001GL09I" 
   class="cuf-url forceOutputURL">https://cropredy-dev-ed.my.salesforce.com/5001W00001GL09I
</a>

As target= is not specified, it default to _self

|improve this answer|||||

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.