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
Eager-2-LearnEager-2-Learn 

Email Template with HREF tag?

Hi,

 

I am trying to use the href html tag in an email template.  When the email comes through it looks just like I enterd it on the template when I am in edit mode!!!

 

Can email templates use html tag and if they can, how can I get the href tag to work.

 

See below which is not working in an HTML template...

 

HTML Edit Mode:

Name: <a href="https://na7.salesforce.com/{!Opportunity.Id}">{!Opportunity.Name}</a>

 

 

Results in the email: 

Name: <a href="https://na7.salesforce.com/006A0000009NRAP">Edge SLA TESTING</a>

 

Best Answer chosen by Admin (Salesforce Developers) 
Imran MohammedImran Mohammed

You have to use

Name: {!relatedTo.Name}
Stage: {!relatedTo.StageName}
Effective Date: {!relatedTo.Effective_Date__c}

 

For all the fields being referenced using Opportunity should use {!relatedTo.FieldName}

All Answers

Imran MohammedImran Mohammed

Looks like you are using Text based email template.

Try using Custom Email template and it should resolve your issue.

Eager-2-LearnEager-2-Learn

Thank you for responding.  Can you be more specific when you say custom email template?

 

I am clicking on Setup | Peronal Setup | My Personal Information | Email | My Templates.

 

I created a template and clicked the 'Edit HTML Version'.  It even says it is an HTML Preview.  If that is not does not allow for HTML tags then why do they call it HTML Version?

 

I appreciate your support.

Imran MohammedImran Mohammed

I actually use such kind of html tags in my email templates and it works fine with me.

Make sure that your anchor tag is not missing anything.

Let me know if it still does not work.

 

Eager-2-LearnEager-2-Learn

I included the exact tag above but here it is again.

 

HTML Edit Mode:

Name: <a href="https://na7.salesforce.com/{!Opportunity.Id}">{!Opportunity.Name}</a>

 

 

Results in the email: 

Name: <a href="https://na7.salesforce.com/006A0000009NRAP">Edge SLA TESTING</a>

 

 

I used this example below and my HTML tag above looks correct.  The only difference is that I have the {} reference to the Id within the quotes.  Is the something special that I have to do there?

 

<a href="http://www.w3schools.com">Visit W3Schools.com!</a>

 

Imran MohammedImran Mohammed

I even used {!Opportunity.name} in the anchor tag and it worked fine for me.

I did the same using my custom object and it worked fine for me.

 

Try using Visualforce email template and see if it is feasible for you.

 

Eager-2-LearnEager-2-Learn

I am doing workflow 101 (point and click) and the only option I see is to select an email template when I am creating the email alert.  I do not see an option to choose a VF page (assuming you are saying to create a VF page).

Imran MohammedImran Mohammed

I did not mean Visualforce page. When you try to create an email template. You will see one of the listed radio options as Visualforce email template.

Eager-2-LearnEager-2-Learn

Ok, getting crazy fun now!

 

I found the option and created the VF template but I am still learning all this stuff and do not know VF syntax yet.

 

The VF template is:

<messaging:emailTemplate subject="Opportunity Sold Alert" recipientType="User" relatedToType="Opportunity">
<messaging:htmlEmailBody >
    <b>Opportunity Sold Alert</b><br></br><br></br>
    Name: <a href="https://na7.salesforce.com/{Opportunity.Id}">{Opportunity.Name}</a><br></br>
    Stage: {Opportunity.StageName}<br></br>
    Effective Date: {Opportunity.Effective_Date__c}<br></br>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

 

 

 


The resulting email produces what is shown below.  How can I reference the field names within the VF template?

 

Opportunity Sold Alert

Name: {Opportunity.Name}
Stage: {Opportunity.StageName}
Effective Date: {Opportunity.Effective_Date__c}

Imran MohammedImran Mohammed

You have to use

Name: {!relatedTo.Name}
Stage: {!relatedTo.StageName}
Effective Date: {!relatedTo.Effective_Date__c}

 

For all the fields being referenced using Opportunity should use {!relatedTo.FieldName}

This was selected as the best answer
Imran MohammedImran Mohammed

For User you should use,

{!recepient.Name}

 

Let me know if the relatedTo solution worked.

Eager-2-LearnEager-2-Learn

Yes it did work.  That was painful! :smileyvery-happy:

 

Before you sent me the solution I also got it working by selecting the Custom HTML option but since I have to start learning VF I think I will go with the VF version.  Thank you very much.

 

Oh, one last quesiton do you have a link to the documentation that pointed you to the RelatedTo and Recepient portion?

 

<messaging:emailTemplate subject="Opportunity Sold Alert" recipientType="User" relatedToType="Opportunity">
<messaging:htmlEmailBody >
    <b>Opportunity Sold Alert</b><br></br><br></br>
    Name: <a href="https://na7.salesforce.com/{!RelatedTo.Id}">{!RelatedTo.Name}</a><br></br>
    Stage: {!RelatedTo.StageName}<br></br>
    Effective Date: {!RelatedTo.Effective_Date__c}<br></br>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

Imran MohammedImran Mohammed

I think you can find the info relating to Visualforce email template in Visualforce guide.

Gopi chand 11Gopi chand 11
I have tried like below its working :
 '<b>Quote Number:</b> '     + '<a href="'+URL.getSalesforceBaseUrl().toExternalForm() + '/' + BigQuote.Id+'">'+BigQuote.Name+'</a>'+ '<br/>' +