0

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?

1 Answer 1

4

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.

4
  • Thank you for your answer. The link part seems pretty straightforward, but how can I distinguish an internal from an external user, since the user records are on the same table (and have the same prefix)? Commented Nov 22, 2017 at 14:30
  • Figured out that the simplest way of doing so is to create a "default community" field on the user object and get it there. If the field is blank, then there's no community. Commented Nov 22, 2017 at 15:44
  • 1
    Yea, or as I already wrote in my answer, you can look at the ContactId field. Community users are always linked to a contact, thus that field will have a value. Internal users will not have a value there.
    – Folkert
    Commented Nov 23, 2017 at 8:13
  • Now I get it. That's even better. :) Commented Nov 23, 2017 at 10:25

You must log in to answer this question.

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