We have a Visualforce page that provides a sophisticated graphical presentation of data, and part of this is to include links to open various objects' record pages when the link text is clicked. We do this by generating the required URL using, for example:
The URL generated this way points to a Classic record page (because the context of generation is a Visualforce page). Normally this is not an issue when the user has Lightning Experience enabled because Salesforce dynamically redirects to the equivalent Lightning record page.
However, when this VF page is used in a Community (with LEX enabled) then this redirection doesn't occur and the user ends up on the Classic record page.
We would like the link to always navigate to the Lightning record page when the user has LEX enabled, whether or not the usage is in a Community.
How can we achieve this without using relative paths? We can't use a relative path because when accessed through a Community, that community's site may have a URL step defined.