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 mydomain.my.salesforce.com or mydomain.lightning.force.com.

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 
 
@AuraEnabled   
        public static string getmydomain(){   
        String urlInstance=String.valueof(System.URL.getSalesforceBaseURL().gethost());
          String s2=urlInstance.removeEndIgnoreCase('.my.salesforce.com');
            return s2;
        }

--
Thanks,
Prashant
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?
LinThawLinThaw
hi,

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.

Regards,
LinThaw
DeeptiShuklaDeeptiShukla
Hi, How can we do this inside a flow?