[SalesForce] Dynamic domain/link in Email Alerts

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.

Best Answer

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.

Related Topic