Monday, January 11, 2016

Salesforce HYPERLINK expression and communities

Problem


A text formula field providing a url as follows doesn't work for a named community, so only works internally.

HYPERLINK( "/"+Parent_Custom_Object__r.Id, Parent_Custom_Object__r.Name,"_self")

e.g. if you have a community called mysite, you want the following url for users logging into this site

https://mysite-mydomain.instance.force.com/mysite/0ZZ123DEF456GHI

but instead you get

https://mysite-mydomain.instance.force.com/0ZZ123DEF456GHI

which only works for internal users and gives an Under Construction error for communities users.

Solution

HYPERLINK( LEFT($Api.Partner_Server_URL_260, FIND( '/services', $Api.Partner_Server_URL_260))+Parent_Custom_Object__r.Id, Parent_Custom_Object__r.Name,"_self")

Since the Partner_Server_URL_nnn is served up by the $API variable, I thought it wouldn't be sensitive to user context. But it is, which means this works for communities! It could be either $API or the UI itself which is converting to a communities-friendly URL, I don't know which.