1

Template:

 <!DOCTYPE html>
<html>
<body>
<p><b>{!Contact.FirstName},</b><br>
<p>Please follow: <a href="https://www.google.com/">John Smith</a><p>
</body>
</html>

Apex:

EmailTemplate template = [SELECT Name,Body,DeveloperName,HtmlValue,Subject FROM EmailTemplate WHERE DeveloperName ='GuestMail'];
     for(Contact c : scope){ 
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
     email.setTemplateId(template.Id);
                    email.setTargetObjectId(c.Id);
     Messaging.SendEmailResult[] responseList = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
    if(responseList[0].isSuccess()){
                        Contact con = new Contact();
                        con.Id = c.Id;
                        con.Status__c =  c.Status__c;
                        con.Status_Time__c = c.Status_Time__c;
                        contactListToUpdate.add(con);
                    }

Output:

enter image description here

Let me know where am I going wrong. Thanks!

2 Answers 2

1

@Siddhant Singh, Please follow below mentioned steps:

  • Firstly, you need to create an HTML Email Template
  • In the body mention a "Link" word (which should be displayed as a link)
  • Then you need to highlight the "Link" word and then click on hyperlink icon on the Formatting Controls toolbar
  • you need to specify the path only where it needs to be redirected on click
2
  • Hi Ravi, please go through the custom classic email template, we don't have the option to hyperlink there. Further this link will be dynamic, therefore can not go by the method you described. Commented Feb 7, 2022 at 7:28
  • Can you refer this link - salesforce.stackexchange.com/questions/188818/… (Screenshots are attached)
    – Ravi Teja
    Commented Feb 7, 2022 at 8:00
1

The code and the template mentioned was fine. The issue was with the email service provider, Google was blocking the link whereas in outlook it rendered.

You must log in to answer this question.

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