7

I'm trying to add a hyperlink to a string which will form the body of an email that I'm sending from an Apex class.

subject = 'Please give us your feedback';
body = '<html lang="ja"><body>'+
       '<br><br>'+'Dear '+FirstName+
       '<br><br>'+'Some text'+
       '<br><br>'+'we’d like to complete a short survey.'+
       '<br><br>'+<a href="https://www.surveymonkey.co.uk">Take the survey now.</a>+
                        '<br><br>'+'Kind regards,'+
                        '<br>'+'Company Name';

But I'm getting an error:

unexpected token: '<'

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

I've found plenty of examples which demonstrate how to include hyperlinks in VisualForce emails but none when the string is in a standard Apex class, is this possible?

1 Answer 1

8

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>'+
2
  • @AlexS awesome.. :)
    – Ratan Paul
    Commented Apr 13, 2016 at 14:17
  • 1
    This answer is the reason why I prefer to use Dom.Document to form well-structured XML or HTML.
    – sfdcfox
    Commented Apr 13, 2016 at 21:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .