[SalesForce] Get community link in email template

In the Visualforce page context, we have the $Site.Prefix formula available to get the community's path prefix so we can adapt our link for the internal users.

I'm wondering if something similar can be achieved on Visualforce Email Templates. For example, if I have a community user that should get an automated email with a link for a record. The link must be company.force.com/community/<record_id> instead of company.my.salesforce.com/<record_id> for internal users. Is it possible to dynamically detect the users's community?

Best Answer

I had a similar use case with a partner community. After extensive search, I couldn't find a proper solution, so we used the following workaround.

We used a Custom Label to store the Community URL and then reference it in the Visualforce Template like this:

<apex:outputLink value="{!$Label.Partner_Community_URL  & '/' & relatedTo.Id}" >{!relatedTo.Name}</apex:outputLink><br/>

So save the value of https://company.force.com/community in a Custom Label you create.
You could add a rendered attribute to the outputLink element based on the value of relatedTo.ContactId, which will be filled for external users.

Related Topic