1

I've created a Custom Email Template. In the HTML Email Content, a few fields are displayed and I've created a button with a link

<a href="https://c.cs15.visual.force.com/apex/PortalCasePage?id={!Case.Id}" class="btn-Open-Case">Open Case</a>

to direct the customer to the Portal Case Page. This is working in one environment. To make this work in the other environments where the URL changes, I'm trying to make use of the getSalesforceBaseUrl(). We have an URL helper class that returns the appropriate URL. But how do I merge that in this HTML link? Thanks in advance.

3 Answers 3

2

To get the string value of the base url use:

String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm()

then append the '/' + your other parameters you may need

Assuming your URL helper class is not named URL

Also, you will probably need to change to a VF email template. Look for other answers though that may have a way to do it in the HTML template. (One clunky way is to populate a field on the case that holds the base URL and use a trigger to set the value. Then you could use that in the custom HTML email template. Or use a custom setting)

6
  • I believe he is using a Custom HTML email template and not Visualforce email.. will he be able to access apex from custom html emails ? Commented Aug 26, 2014 at 1:18
  • Ahh, need to read closer, I believe the OP will need to change to a VF template.
    – Eric
    Commented Aug 26, 2014 at 1:26
  • Thank you @Eric. Yes, I came up with two approaches. First, by using custom settings. And second, like you said, setting the value of a field by using a trigger. But I was curious to know if we can pull the baseURL from the HTML Email Content of a custom template.
    – Seesh
    Commented Aug 26, 2014 at 3:12
  • You can use System.URL.getSalesforceBaseUrl().toExternalForm() if you name your class URL Commented May 24, 2017 at 21:25
  • @ScottPelak - If you have a class named URL or any class using the same name as a system method it is highly encouraged to change it.
    – Eric
    Commented May 24, 2017 at 21:28
1

You can simply use, this will solve your problem.

href='{!Case.Link}' target='_blank' >{!Case.CaseNumber}

between anchor tag i.e. a

0

To get Base URL just simply use

{!MID(Account.Link, 1, LEN(Account.Link)-15)}

This will give you Base URL. Were Account.Link is standard field in Email Template for Account Object. Similarly you can get this Link fields for all objects in email Template.

If you want related record Link in Email Template then simply use

{!MID(Contact.Link, 1, LEN(Contact.Link)-15)}{!Contact.AccountId}

You must log in to answer this question.

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