I am trying to get the org domain in a lightning comp and use that to redirect to the QLE of a record. For some reason, I am receiving undefined on my helper fucntion that calls a nother helper function, which gets the org domain from the apex controller. Can someone point why I am getting this issue? Here are snippets of my code.

//Apex Controller

    public static string getDomain(){   
        String url = String.valueof(System.URL.getSalesforceBaseURL().gethost());
        String url2 = urlInstance.removeEndIgnoreCase('.my.salesforce.com');
        return url2;


fetchDom: function(component, event, helper, result) {

    var orgDom = component.get("c.getDomain");
    console.log('orgDom: ', orgDom ); **//THIS IS GETTING RESULT**

    orgDom.setCallback(this, function(response) {
        var result = response.getReturnValue();
        console.log('result: ' +  result);
        return result;
rediRectToUrl: function (component, event, helper, result) {
    let recordId = result;
    var myDomain = this.fetchDom(component, event, helper, result);
    console.log('myDom:', myDom); **//THIS IS GETTING UNDEFINED**

    var urlEvent = $A.get("e.force:navigateToURL");
      "url": 'https://' + myDomain + '--sbqq.visualforce.com/apex/sb?scontrolCaching=1&id=' + recordId + '#quote/le?qId=' + recordId

1 Answer 1


You didn't call $A.enqueueAction, so the server was never called. In addition, server calls are asynchronous, so you need to wait for the result. We do this with a Promise. In addition, you called the variable myDom at one point, and myDomain at the other.

  fetchDom(component) {
    return new Promise((resolve, reject) => {
      const orgDom = component.get('c.getDomain')
      orgDom.setCallback(this, function (response) {
        const status = response.getState()
        if (status === 'SUCCESS') {
        if (status === 'ERROR') {
  rediRectToUrl(component, event, helper, result) {
    const recordId = result
    this.fetchDom(component).then((myDomain) => {
      console.log('myDomain:', myDomain)
      const urlEvent = $A.get('e.force:navigateToURL')
        url: `https://${myDomain}--sbqq.visualforce.com/apex/sb?scontrolCaching=1&id=${recordId}#quote/le?qId=${recordId}`,
  • Hi @sfdcfox Thanks for answering! I tried your code but I wasn't redirected to the QLE. I noticed on my logs that It is entering the rediRectToUrl function but not even entering this part console.log('myDomain:', myDomain) within the same function. Any thoughts?
    – Charlie
    Nov 28, 2021 at 23:11
  • @Charlie Are you getting any errors? Try adding a console.log inside the callback to see what the state and return values are, or if you're getting an error.
    – sfdcfox
    Nov 28, 2021 at 23:27
  • Yes I added console logs on the setcallback of fetchDom to see the the state it is entering but the logs aren't showing up. It seems like it is not even entering the fetchDom function. I have a console log as well before the "this.fetchDom(component).then((myDomain) => {" line on rediRectToUrl function, and that is showing up. The logs after that line however, don't.
    – Charlie
    Nov 28, 2021 at 23:37
  • @Charlie Fair enough. One sec, I'll reproduce in my org so I can troubleshoot.
    – sfdcfox
    Nov 28, 2021 at 23:38
  • @Charlie typo was in my code. getStatus should have been getState. Give that a try.
    – sfdcfox
    Nov 28, 2021 at 23:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .