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
Sarita Pa 3Sarita Pa 3 

How to get salesforce base url in lightning

Hi All,
Good Day.

Could you help me how to get salesforce base url for lightning.

Thanks and Regards,

venkata

Raj VakatiRaj Vakati
You can simply reference the apex class as your server side controller and fetch the value on the client side?
 
public with sharing class theorgurl {

    @AuraEnabled
    public static String fetchit(){
        string urler = URL.getSalesforceBaseUrl().toString();
        return (urler);
    }
}
 
"geturl" : function(cmp) {

        var action = cmp.get("c.fetchit");
        action.setParams({ urlname : cmp.get("v.urlname") });

        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
             ...Do something with response.getReturnValue()...
        }
}

 
Sarita Pa 3Sarita Pa 3

Hi Raj,
Thanks for your quick reply. I am really sorry for not putting that i need the url in apex class not in lightning component.

Thanks and Regards

Thanks and Regards,
ve

venkata

Raj VakatiRaj Vakati
try this


getOrgDomainUrl() always returns the same domain for your org, regardless of context. Use this method to build links to record URLs that work both in Lightning Experience and in Salesforce Classic, or as the domain when making API calls to your org.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_url.htm
 
Url.getOrgDomainUrl().toExternalForm()