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
Sarthak BhatnagarSarthak Bhatnagar 

Adding clickable text (hyperlink) in Apex Class

I have an Apex class that I am using as a custom controller to send an email from a VF page. In that class I have constructed the email subject and body to have predefined text but the user still has the option to edit/add on to it on the VF page.
PROBLEM: I am trying to add a link to the email body in the constructor in the Apex class so that the person receving the email can directly go the record that the email is refering. 

This is an example of the body text: 
String body = 'Hi ' + Contact.FirstName + ', \n' + 'This is the account I am talking about + (hyperlink) acc.Name +  ' Lets discuss some more." 

I have tried constructing a string with an href: 
String link = '<a href="https://www.surveymonkey.com>' + acc.Name + '</a>';

But that just prints the whole string, along with the link, and doesn't make the acc.Name hyperlink. 
I also tried adding a commandLink on the VF page between the body tags but that doesn't work either. 
Any input is appreciated. 
 
Deepali KulshresthaDeepali Kulshrestha
Hi Sarthak,

Instead of using
'<br><br>'+<a href="https://www.surveymonkey.co.uk">Take the survey now.</a>+

try to add your link inside single quote like

'<br><br><a href="https://www.surveymonkey.co.uk">Take the survey now.</a>'+

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
Chander GhorelaChander Ghorela

@Sarthak Bhatnagar,

Did you get the solution ?

@Deepali, this doesnot work at all.