Scenario: I am using Salesforce sites to display a form where a user can enter some data. When a user finshes, I have an email alert setup with a link in it to send the user to another page on the site.

Problem: Setting the URL on the link in the email alert to direct to the Sandbox version of the site if the email is being tested from Sandbox, and vice-versa for Production. None of the $Site global variables assist here because the email alert does not come from the Site domain. I'd rather not hard-code this information.

2 Answers 2


Just came up w a simple solution that works for email alerts, I think it would work for a site but have not tested.

Create a formula field on User with the following structure (which I got from this SE post)

LEFT($Api.Partner_Server_URL_260, FIND( '/services', $Api.Partner_Server_URL_260))

Then use that field in the email alert, with the syntax {!User.FieldName__c}

Per the salesforce docs, the User fields represent the sending user on the email alert, so it should always be populated.

User Fields—Use these merge fields to represent the sending user. Merge fields named {!User.field_name} return values from the user record of the person who created or updated the record that triggered the workflow rule.

This is working on email alerts in my instance. I previously would create formula fields on each object using the Partner URL, but was looking for a way to only create one field and reference it. Since global variables are not accessible, this solution came to mind. Let me know if it works on sites, I think it should.


The solution I've come up with is to use a Custom Label as a placeholder for the URL. Then it is just a matter of referencing $Label.label_name in the Email Templates for the url, and then there is only one place to update the Domain after moving to Production.

I would love to hear other ways though!

  • This is not environment/sandbox free. To avoid post deployment step of editing the URLs in email templates we can use a formula field - LEFT($Api.Partner_Server_URL_360, FIND( '/services', $Api.Partner_Server_URL_360)) and the use this formula field in merge fields
    – Jarvis
    Commented Jul 4, 2018 at 7:58

You must log in to answer this question.

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