function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael Kolodner 13Michael Kolodner 13 

Get the My Domain URL in my Lightning component controller?

Is there a simple way, in the controller for a Lightning component, to get the My Domain of the org? I would like to easily know the URL for login of the org this component is displaying in so that I could know or

Literally all I'm looking for is the method to get the string "mydomain"
Prashant Pandey07Prashant Pandey07
Hi Michael,
There are many ways you can get your domain name.. You can create a method and get the domain name for example 
        public static string getmydomain(){   
        String urlInstance=String.valueof(System.URL.getSalesforceBaseURL().gethost());
          String s2=urlInstance.removeEndIgnoreCase('');
            return s2;

Michael Kolodner 13Michael Kolodner 13
OK, I'm starting to understand more as I play with this. It looks to me like the code you gave above would have to be on a server side Apex class. Is there any way to put code directly into the client side controller (the .js file) to grab the base URL?

How about like this?
var hostname = window.location.hostname;
var arr = hostname.split(".");
var instance = arr[0];
If there is any other ways, please share.

Hi, How can we do this inside a flow?