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
Best Answer
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 andnull
or an empty string response for success):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.