I would like to call an @RemoteAction method from a custom button. I am aware that it is already possible to call a WebService method.

The view page of my object is already a visualforce page override, if this increases my options.

I have put the following code into a javascript button

Visualforce.remoting.Manager.invokeAction("TokenInputHelper.getExistingTokens", "{!Project__c.Id}", function(result, event) {
    if (event.status) {
        //TODO: Do something with response
    } else if (event.type === 'exception') {

but I get the following error message, which makes me think this is not possible:

A problem with the OnClick JavaScript for this button or link was encountered: Visualforce is not defined

2 Answers 2


Visualforce includes a bunch of javascript stub methods and helpers based on the controllers used that have @RemoteAction methods in them. Custom buttons lack the intelligence to do this and I believe @RemoteAction calls are not possible in this way from buttons.

That at least would be the official answer, if you were willing to reverse engineer how @RemoteAction methods actually pass data back to the server it may be possible to make an unsupported implementation.

  • AFAIK, this is correct. Visualforce knows how to put in the minimal amount of code required for transporting calls back and forth and without it the necessary JavaScript isn't setup. So the only way I can think to get it to work would be to insure you have VF framed on the page, and refer to the RemoteAction calls from it - but that would be hacky at best.
    – joshbirk
    Aug 7, 2012 at 16:09
  • Thanks for the responses, I'm going to abandon this idea unless Salesforce decides to support it Aug 7, 2012 at 22:58

Whenever I've done remote actions I've put the @RemoteAction in the controller extension for the Visualforce page, and then call it like

ControllerExtension.RemoteMethod(DATA, callback);

I've not see the use of Visualforce.remoting.Manager.invokeAction(...) before.

  • The call in my example is the Salesforce recommended way to prevent namespacing issues, except I bastardised it by not using Visualforce.remoting.Manager.invokeAction("{!$RemoteAction.TokenInputHelper.getExistingTokens}"... (I couldn't use $RemoteAction in a custom button). I just tried the syntax you suggested and it didn't work either. Aug 7, 2012 at 22:55

You must log in to answer this question.

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