You need to sign in to do that
Don't have an account?
SFTechy
Method does not exist or incorrect signature: SalesforceBaseURL.GetSFBaseURL()
Hi, I'm fairly new to APEX. I wrote a class which needs to get the Salesforce base URL of my org instance, so I can append it with a record id. I keep getting the following error message when I execute an anonymous block.
Compile error at line 1 column 1
Method does not exist or incorrect signature: SalesforceBaseURL.GetSFBaseURL()
I'm running this in my sandbox. Whether it be Eclipse or the Developer Console, I get the same error message. Can someone please help? What am I doing wrong? Thank you so much!
Anonymous block syntax:
SalesforceBaseURL.GetSFBaseURL();
public class SalesforceBaseURL {
//public String SFBaseURL;
public static String GetSFBaseURL(){
// Get the dynamic Salesforce base URL
//SFBaseURL = Url.getSalesforceBaseUrl().toExternalForm();
//SFBaseURL = "TESTING";
return 'TESTING';
}
}
Compile error at line 1 column 1
Method does not exist or incorrect signature: SalesforceBaseURL.GetSFBaseURL()
I'm running this in my sandbox. Whether it be Eclipse or the Developer Console, I get the same error message. Can someone please help? What am I doing wrong? Thank you so much!
Anonymous block syntax:
SalesforceBaseURL.GetSFBaseURL();
public class SalesforceBaseURL {
//public String SFBaseURL;
public static String GetSFBaseURL(){
// Get the dynamic Salesforce base URL
//SFBaseURL = Url.getSalesforceBaseUrl().toExternalForm();
//SFBaseURL = "TESTING";
return 'TESTING';
}
}
More info: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_url.htm
When I try your code from the IDE, I get the following error:
---
Compile error at line 6 column 26
Only top-level class methods can be declared static
---
Which suggests to me that anonymous apex actually creates some kind of class to execute your code.
This is borne out when I try to change the static method to an instance one and use that:
as I then get the error:
---
apex.bytecodeinterpreter.InterpreterRuntimeException: Unable to load class: KAB_TUTORIAL/anon$SalesforceBaseURL Error Id: 567088251-343431 (965422512)
---
so I can define the class, but it looks like there's a top level class named 'anon' that my (your!) code is being wrapped in. This doesn't appear to be a real class though, as I can't just use the naming 'anon.SalesforceBaseURL'.
The only way I've been able to get this to work is to save the class to Salesforce first and then execute methods on it via an anonymous block.