How do I get the current Salesforce domain?

I have a button which redirects to a url. I want to avoid hardcoding the domain though since we have sandboxes etc. I want something like https://{{$Site.Domain}}/restofurl.

$Site.Domain doesn’t work like for visualforce pages though. How do I get the domain or even just the organization sub domain in

So we do include some of the Site related global merge variables that are available to day in VF.  But not all of them.  Domain is not currently supported.  Check out this document to see which are available.

Is there a particular reason you need to have an absolute URL? Usually this is only necessary if you are in a Site / Community environment, in which case you can use {{$Site.CurrentSiteUrl}}, otherwise you should just use relative URL’s.

Here’s a quick Javascript hack:'.')[0] 

Is there any reason the $Site.CurrentSiteUrl would be null?  I’m trying to convert an iframe path to a relative url, but that doesn’t work, but I want it to be environment independent.  I’ve testing other global merge variables to make sure my syntax was correct, and they work just not $Site ones, they’re coming back blank.  Any ideas?


Are you building pages for a Community or Site in Salesforce?  I am pretty sure that the $Site global variables only have a value when you are viewing the Skuid pages in a Site or Community.  If you are doing a ‘preview’, this won’t work since you’ll still be in Salesforce.



It’s a page inside of salesforce, normal object view override.  We can’t use a relative url because the iframe won’t load, and we don’t want to update a hardcoded url when we move the xml across our different test environments and into production, so trying to find a way for it to load the environment url dynamically.  Any thoughts?



If Moshe’s Javascript doesn’t work for you, the only thing I can think of is to create a Custom Setting.  Have your page reference the Custom Setting for the URL to the iframe ‘page’.  You would have to set it once for Production and each time your refresh a Sandbox, but your page would be portable.  You might have to change it for Production if your org is split by Salesforce.  You should use My Domain.



I looked around the web to find a solution for this. The only workaround to $Site.BaseUrl I found was this :

var baseUrl = "{!LEFT($Api.Partner_Server_URL_390, 
FIND('/services', $Api.Partner_Server_URL_390))}";
alert("baseUrl: " + baseUrl);

Just Use

{! URLFOR('<restofurl>' + <anyvariabletoadd>) }

Hope this helps

@Paul Did you ever find/develop a solution for this issue? It appears you were attempting something I am running up against right now.

@AndyONE unfortunately I don’t recall. I do use that merge parameter regularly though.

@AndyONE have you been able to find a solution for this?

Can you share more about your specific use case (site or community vs internal Salesforce, iframe, etc)?