How do I get the current Salesforce domain?

edited September 2019 in Questions
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.<br>
$Site.Domain doesn't work like for visualforce pages though. How do I get the domain or even just the organization sub domain in <orgdomain>


  • Rob HatchRob Hatch Skuad, Sonar ✭✭
    edited September 2016
    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.

  • Zach McElrathZach McElrath Skuad
    edited March 2017
    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.
  • Moshe KarmelMoshe Karmel Member
    edited July 2015
    Here's a quick Javascript hack:'.')[0]  
  • PaulPaul Member, Sonar ✭✭
    edited September 2019
    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?

  • edited December 2017

    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.


  • PaulPaul Member, Sonar ✭✭
    edited December 2017
    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?

  • edited December 2017

    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.


  • Nitesh JoshiNitesh Joshi Member
    edited September 2019
    I looked around the web to find a solution for this. The only workaround to $Site.BaseUrl I found was this :
        FIND('/services', $Api.Partner_Server_URL_390))}";<br alt="" title="" name="" value="" type="" target="" rel="">alert("baseUrl: " + baseUrl);var baseUrl = "{!LEFT($Api.Partner_Server_URL_390, <br alt="" title="" name="" value="" type="" target="" rel="">

    Just Use
    {! URLFOR('<restofurl>' + <anyvariabletoadd>) }
    Hope this helps
Sign In or Register to comment.