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
CraigHCraigH 

Sites domain name access in an email template

Is there a way to access the sites domain name in an email template?

 

i.e. I'd like to have a email that is sent on a workflow that will give a link to a sites page.

 

In development, the page would be something like:

 

http://XXX-developer-edition.na7.force.com/mysite/mypage

 

I would like to code the template something like

 

{!siteaddress}/mysite/mypage

 

so when moving to different environments I don't need to edit the tempate.

 

 

 

Or, is there a way to access a static Apex class method in an email template?  This way, I could set the site address in the Apex class so at least if I have many e-mail templates I would only have one place to change it.

Best Answer chosen by CraigH
Ivan VrtacnikIvan Vrtacnik
While Ryan's solution will work, I find it to be overkill for the requirement. Instead, I put the site domain into a custom setting and referenced that setting field in the email template, like so:
{!$Setup.Config__c.Site_Domain__c}<Page Name>?id={!Contact.Id}

All that needs to be done is populate the field value on the custom setting in each environment, a task which an admin can do without the aid of a developer.

All Answers

RyanGuestRyanGuest

How about using a Visualforce email template and then in the VF email template, create a custom component that uses a controller that returns the Site URL?

 

There is currently no way to dynamically  get the Site URL if you're not in the context of a Site.

CraigHCraigH

That would work.  

 

However I was hoping to keep to the basic e-mail templates so a non-technical user could maintain them.

sornasorna

Hi,

From a site page I have to send site url through email template to my users. Is this possible without the help of Visual force email template?

 

Thanks in advance,

sorna

Ivan VrtacnikIvan Vrtacnik
While Ryan's solution will work, I find it to be overkill for the requirement. Instead, I put the site domain into a custom setting and referenced that setting field in the email template, like so:
{!$Setup.Config__c.Site_Domain__c}<Page Name>?id={!Contact.Id}

All that needs to be done is populate the field value on the custom setting in each environment, a task which an admin can do without the aid of a developer.

This was selected as the best answer