I want to execute a call to Lightning Platform REST API in Anonymous window. When I am writing the following:

String sfURL = URL.getSalesforceBaseUrl().toExternalForm(); 

I am getting the following error:

method does not exist or incorrect signature void getSalesforceBaseUrl() from the type String

I have checked and the sandbox URL is specified in the Remote Site Settings, since this is a preliminary condition. I do not know if this is regarding the fact that I use the Anonymous Window to execute the code directly. Is there any restriction for this?

1 Answer 1


That error occurs when you have something else defined as "Url", something like

String url = 'whatever';
String sfURL = URL.getSalesforceBaseUrl().toExternalForm();

In that case, SF understands URL as your variable and not the one you are expecting.

I'd say you have 2 options,

  1. Change your declaration of whatever to a different name
  2. Use System.URL.getSalesforceBaseUrl().toExternalForm(); instead
  • I have tried this as well before writing this question @Sergio Alocer but this was not the cause. I got the same error. Actually I have tried to put the code in a class and then execute it and it worked so the problem is that Anonymous window does not recognize that method for some reason. Thanks for your suggestion. Jun 4, 2020 at 10:56
  • 1
    Have you tried using the System. prefix? In my Execute Anonymous window it works Jun 4, 2020 at 11:21
  • Oh, sorry. You're right. I was not noticing the difference. Indeed, adding that prefix works, but not adding it results in an error. Thank you very much. Jun 4, 2020 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.