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?

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

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.