Continuous Site Switching and My Domain

Our Salesforce Org is about to go through a site switch.

https://help.salesforce.com/articleView?id=Site-Switching-Overview&language=en_US&type=1

We have a lot of instances of apex code which use the following line to provide links to custom visualforce pages.

string imageURL = URL.getSalesforceBaseUrl() + '/apex/mycustompage';

According to several posts and this idea the following method returns the instance name when run within apex / visualforce

https://success.salesforce.com/ideaView?id=08730000000aJpzAAE

which looks something like this

https://xxx–c.na8.visual.force.com/apex/myPage

What we would like is to get a URL without the instance name like so:

https://xxx.my.salesforce.com/apex/myPage

It seems the only way to overcome this issue is to use a custom setting and store our custom domain URL as outlined in the idea post.

Is there any other way to return the my domain URL?? ( besides the SOQL query which requires Setup and Configuration Profile Permission OR using a custom setting ).

We are also going to be changing the my.domain in the future and this causes issues with both storing links in the database and sending emails to users with these address.

Answer

Perhaps the answer is not to go in this direction, but to use relative URLs or to use PageReference in Apex to navigate directly to a Visualforce page. You can add page parameters to the page you’re navigating to.
Lots of work, I know, but it’s also a best-practice, as it enforces checking if the page exists and prevents deletion of the page if you have Apex code referring to it.

Attribution
Source : Link , Question Author : Benjamin Pirih , Answer Author : DavidSchach

Leave a Comment