How do I get the current Salesforce domain?

  • 1
  • Question
  • Updated 11 months ago
  • Answered
  • (Edited)
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?
Photo of Matthías Ragnarsson

Posted 3 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
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
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
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.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Here's a quick Javascript hack:

window.location.host.split('.')[0]
Photo of Paul

Paul

  • 442 Points 250 badge 2x thumb
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?
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,426 Points 10k badge 2x thumb
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
Photo of Paul

Paul

  • 442 Points 250 badge 2x thumb
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!
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,426 Points 10k badge 2x thumb
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