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.
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.