I am sending sample survey email to users whenever accounts meets particular criteria.

I created a apex class and iam accessing contacts and sending contact details to below SendEmail method.Now i am attaching a link within email template through HTML body but i dont want to send long link to the user.

Is there any way to hyperlink above link to small text or clickable image.

Like Below:


My code looks like:

public Static void sendMail(Id accountdetails,String Emaildetails,Id Contactdetails,Id CaseId,String Customername,String Accountsname)
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        List<String> sendTo = new List<String>();
        mail.setSenderDisplayName('Azuga Telematics');
        mail.setsubject('Invitation to participate in survey');
        String body = 'Hi '+Customername+','+'<br/>'+'<br/>';
        body += 'Account Name:'+'<br/>'+'<br/>';
        body += Label.Churn_Site_Details+'&cId='+Contactdetails+'&caId='+CaseId;
        Messaging.SendEmailResult[] results = Messaging.sendEmail(
                                 new Messaging.SingleEmailMessage[] { mail });

As per @James i had updated my code:

body += '<a href="+Label.Churn_Site_Details+'&cId='+Contactdetails+'&ca‌Id='+CaseId+">
  <img border="0" alt="Link" src="https://cs72.salesforce.com/0155D0000004ryk" width="100" 

Expression cannot be assigned


You could use a href. This should work:

body += '<a href="'+Label.Churn_Site_Details+'&cId='+Contactdetails+'&caId='+CaseId+">Link to Record</a>'
  • Any Posibility href to button click Or image
    – Pavan tej
    Nov 2 '17 at 14:54
  • You could replace the link text with an image: body += '<a href="'+Label.Churn_Site_Details+'&cId='+Contactdetails+'&caId='+CaseId+"><img border="0" alt="Link" src="http://imageurl.gif" width="100" height="100"></a>' Nov 2 '17 at 14:57
  • Thanks is there any way to reference images from docs in abovde link
    – Pavan tej
    Nov 2 '17 at 15:07
  • Yes you can, just open the document, and copy the image url. Just make sure that it's externally available. Nov 2 '17 at 15:15
  • I got an error like Expression cannot be assigned will you please check i updated my question
    – Pavan tej
    Nov 2 '17 at 15:38

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.