5

My Use case is: As a CustomerCommunity user, I want to login and click on change_password link that redirects me to change_password page in AngularJs, which calles the changePassword method using javascript remoting, so that I can change my password. Issue: This method returns pageReference as null. this is my code: Visualforce Page:

    <apex:page controller="CustomCommunitiesLandingController" docType="html-5.0">
    <script>
     function  chgPwd() {
       var newPassword = document.getElementById('newPwd').value;
       var verifyNewPassword = document.getElementById('verPwd').value;
       var oldPassword = document.getElementById('oldPwd').value;
         Visualforce.remoting.Manager.invokeAction(
         '{!$RemoteAction.CustomCommunitiesLandingController.changePassword}',newPassword,verifyNewPassword,oldPassword,
         function(result, event) {
           alert("result");

         });
         } 
    </script>
     <div class="bootstrap"  >
    oldPwd <input type="text" id='oldPwd' />
     newpwd<input type="text" id='newPwd' />
     verpwd<input type="text" id='verPwd' />
     <h1 align="center">Click The Button</h1>
     <button onClick="chgPwd()" class="btn btn-lg btn-default btn-block">change password</button> 
     </div>
    </apex:page>

Controller Method:

    @remoteAction
    public static String changePassword(string newPassword, string verifyNewPassword, string oldPassword){
    pageReference pr;
    string success;
    pr = Site.changePassword(newPassword, verifyNewPassword, oldPassword);
    if(pr != null){
        success = 'true';
    }else {
        success = 'false';
    }
    return success;
}

Any help is greatly appreciated!

Thank you, Devayani

1 Answer 1

5

The methods of the Site class are designed to work from Visualforce and within a Site so it is possible that the call can't be made to work in your situation. If the context was Visualforce, errors would be available in the ApexPages.getMessages() collection and you could convert them into some other format for your response (e.g. an error string response for a failure and null or an empty string response for success):

for (ApexPages.Message m : ApexPages.getMessages()) {
    // Add messages to your response string
}

but that ApexPages.getMessages() call may not work at all in a @RemoteAction. Try it and see.

In an Angular app that I wrote, I ended up using separate Visualforce pages for calls like this one (separate from the main Angular Visualforce page) which was not what I wanted to do.

1
  • Site.changePassword does not work in Apex REST service too
    – Kaon Z
    Commented Oct 30, 2017 at 4:48

You must log in to answer this question.

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