Im trying to launch a flow from a button using javascript. In my code so far I have:


String base = URL.getSalesforceBaseUrl();

However when I click the button I get:

Unexpected identifier

instead of the URL. What is it I am missing?


You can't call Apex Code methods like that; you're in a JavaScript context. You'll probably want to start off with something like this:


var baseUrl = sforce.apex.execute('Utils','getSalesforceBaseUrl', {});

You'll need a corresponding class:

global class Utils {
    webservice static string getSalesforceBaseUrl() {
        return URL.getSalesforceBaseUrl();

You might also have different options available, depending on your exact context. This is only one possible option. For example, you could write a Visualforce page with a trivial controller:

<apex:page contentType="text/plain" controller="Utils" 
           showHeader="false" sidebar="false" applyHtmlTag="false"
           standardStylesheets="false" showChat="false">{!salesforceBaseUrl}</apex:page>

With the appropriate method in Utils:

    public string getSalesforceBaseUrl() {
        return URL.getSalesforceBaseUrl();
| improve this answer | |

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.