I need to remotely call an apex method in a Visualforce controller, but the JavaScript code is not working.

Controller method:

global with sharing class MemberPoliciesController {

    global static String resetPassword() {
         return 'Test';

JavaScript remoting:

<apex:page standardController="contact" extensions="MemberPoliciesController" showHeader="true" sidebar="true">
        function changePassword() {
            sforce.connection.sessionId = "{!$Api.Session_ID}";
            alert("I am here");
                function(result, event) {
                    if (event.status) {
                    } else if (event.type === 'exception') {
                    } else {
                {escape: true}
  • What does the page look like? Is the controller amongst its attributes? Commented Aug 6, 2015 at 18:30

2 Answers 2


When you invoke the action, you are including an extra comma that is causing problems.

invokeAction() requires a list of parameters and you can't do this with ,, which is what you have. Since you are not passing a parameter, just take out one of the commas and pass the handler function, like this:

  function(result, event){
  • This would be the issue, I wasn't sure if the extra ',' was needed for a no parameter method. Thanks! Commented Aug 6, 2015 at 18:36
  • Cool - I just thought I'd say that I also use the syntax used by @NSjonas. It reads a little more clearly, IMO. If this answer cleared up the issue, you can mark it as accepted. Commented Aug 6, 2015 at 18:42

I prefer using the following syntax:

className.methodName([parameters (optional) ... ,] function(result, event) {
    if (event.type == 'exception') {
       //handle exception 
       //do something with result

Keep in mind JS is case sensitive

You must log in to answer this question.

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