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


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


which looks something like this


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


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.

1 Answer 1


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.

  • Relative URLs or PageReferences will not work for any link that is required to be opened outside of the Salesforce ORG. Envision sending a link to Salesforce users which say they need to take action on a certain item within Salesforce via email. Page parameters are great but we still need to establish a valid end point URL ( without instance name ). This is what my domain is supposed to do but without being able to programatically retrieve the domain we are forced to store it in a custom setting. ( this may be the solution ) Feb 14, 2018 at 14:28

You must log in to answer this question.

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