How do I get the current Salesforce domain?

edited September 19, 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>.salesforce.com?

Comments

  • Rob HatchRob Hatch 💎💎💎
    edited September 1, 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. 

    http://help.skuidify.com/m/11720/l/187263-global-merge-variables-functions


  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited March 2, 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.
  • edited July 15, 2015
    Here's a quick Javascript hack:
    window.location.host.split('.')[0]  
  • PaulPaul ✭✭
    edited September 19, 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?

  • Bill McCulloughBill McCullough 💎💎
    edited December 15, 2017
    Paul,

    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.

    Thanks,

    Bill
  • PaulPaul ✭✭
    edited December 16, 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?

    Thanks!
  • Bill McCulloughBill McCullough 💎💎
    edited December 16, 2017
    Paul,

    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.

    Thanks,

    Bill
  • edited September 19, 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="">
    OR

    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)?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!