function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anton YoganathanAnton Yoganathan 

Hyper link in apex class

Hi,

how can i bring out something similar to 
"

<a href="Https://www.google.com">Search</a>

"

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 clicj=king on it should direct to me to the link on the href.
"
Test
"
'String stringURL  = '<a href='+fullFileURL+' >Test</a>/>';   this does no work..

Virendra ChouhanVirendra Chouhan
Hi Anton,

You can use LinkUrl field of FeedItem sObject
i.e.
post.LinkUrl =URL.getSalesforceBaseUrl().toExternalForm()+ ' / ' + Feed.id;

Regards
Virendra

Anton YoganathanAnton Yoganathan
Hi Virendra,

Thanks for the reply...
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  = '<a href='+fullFileURL+' >Test</a>/>';

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

Thanks,
Anton


Anton YoganathanAnton Yoganathan
<a href="Https://www.google.com">Search</a>

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

Now i understand what you want.
but i think  you cannot use rich HTML in chatter posts. You'll need to include the full URL text as part of the post.
and if you find a way then tell me also (i am also searching for that ).

Regards
Virendra 
version7.7@hotmail.com (mailto:version7.7@hotmail.com)
Tad Aalgaard 3Tad Aalgaard 3

You can use HTML by adding post.isRichText = true;  Make sure your api version is 35.0 or above on your Apex code metadata setting.

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_feeditem.htm - see isRichText on this page