2

I want to return a string value back to the flow. Got it this far, and also I am able to get the return value when I am not in an invocable method.

Here is the error I am getting - Method does not exist or incorrect signature: void getSalesforceBaseUrl() from the type Invocable_GetBaseUrl.BaseUrl

What is wrong in the below code -

global with sharing class Invocable_GetBaseUrl {

    @InvocableMethod(
        label = 'Method to Extract Base URL'
        description = 'Method to Extract Base URL'
    )
    global static List<BaseUrl> GetBaseUrl() {      
        List<BaseUrl> baseUrl = new List<BaseUrl>();
        BaseUrl url = new BaseUrl();
        url.theBaseUrl = URL.getSalesforceBaseUrl().toExternalForm();
        baseUrl.add(url);        
        return baseUrl;
    }
            
    global class BaseUrl {
        @InvocableVariable(
            label = 'BaseUrl'
            description = 'Variable to store Base URL'
        )
        global String theBaseUrl;
    }          
}

1 Answer 1

4

The problem you are having is an overloaded URL token

url.theBaseUrl = URL.getSalesforceBaseUrl().toExternalForm();

the compiler thinks that URL.getSalesforceBaseUrl() is referring to your declared variable url. Apex is not case sensitive

you can fix this in many ways. Here is an obvious one:

BaseUrl bUrl = new BaseUrl();
bUrl.theBaseUrl = URL.getSalesforceBaseUrl().toExternalForm();
baseUrl.add(bUrl); 
return baseUrl;

Or, you can do this:

    BaseUrl url = new BaseUrl();
    url.theBaseUrl = System.URL.getSalesforceBaseUrl().toExternalForm();
    baseUrl.add(url);
    return baseUrl; 

Or, more O-O:

global static List<BaseUrl> GetBaseUrl() {      
    return new List<BaseUrl> {
           new BaseUrl(URL.getSalesforceBaseUrl().toExternalForm())
           };
}
        
global class BaseUrl {
    @InvocableVariable(
        label = 'BaseUrl'
        description = 'Variable to store Base URL'
    )
    global BaseUrl(String val) {this.theBaseUrl = val;}
    global String theBaseUrl;
} 
3
  • Oh my goodness, was it that easy. Thanks cropredy
    – sumchans
    Commented Apr 30, 2021 at 17:47
  • 1
    I gave you another option; see above
    – cropredy
    Commented Apr 30, 2021 at 17:48
  • Thanks cropredy, that looks neat.
    – sumchans
    Commented Apr 30, 2021 at 17:49

You must log in to answer this question.

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