You need to sign in to do that
Don't have an account?
Francesco Sciuto
In ForgotPassword display error message in VF page in case username is not existing
Hello,
I am currently implementing in our SF Community a customized Login flow and the ForgotPassword functionality is part of that. In the ForgotPassword page I use an APEX inputText for the Username, an outputText for the custom Error message and a commandLink to submit the action request:
Apparently my reasoning is not correct since Salesforce documentation (here (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_sites.htm#apex_System_Site_forgotPassword)) states:
The return value (of ForgotPassword) will always be true unless it’s called outside of a Visualforce page. If it's called outside of a Visualforce page, it will be false.
This statement also explains why my Test Methods always fail (not called from a VisualForce page but from a test class, always success = false).
I find this implementation of the Site.ForgotPassword really weird and I would like to know whether I am somehow making a mistake or there is an alternative way to implement this functionality by using the Site.ForgtoPassword site.
I am currently implementing in our SF Community a customized Login flow and the ForgotPassword functionality is part of that. In the ForgotPassword page I use an APEX inputText for the Username, an outputText for the custom Error message and a commandLink to submit the action request:
<div id="loginErrors" class="errors"> <apex:outputText value="{!$Label.Communities_Login_WrongUsername}" rendered="{!isWrongUsername}"/> </div> <apex:inputText id="username" value="{!username}" html-placeholder="Username"/> <apex:commandLink id="submit" value="SUBMIT" action="{!forgotPassword}"/>The VF page is bind to the ForgotPasswordController:
public PageReference forgotPassword() { PageReference result; boolean success = Site.forgotPassword(username); PageReference pr = Page.ForgotPasswordConfirm; pr.setRedirect(true); if (success) { result = pr; } else { isWrongUsername = true; } return result; }My assumption was that in case the username is not found, the Site.ForgotPassword(username) function would return success = false and therefore I give to the user the same page after setting the IsWrongUsername to true, in order to show the error message.
Apparently my reasoning is not correct since Salesforce documentation (here (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_sites.htm#apex_System_Site_forgotPassword)) states:
The return value (of ForgotPassword) will always be true unless it’s called outside of a Visualforce page. If it's called outside of a Visualforce page, it will be false.
This statement also explains why my Test Methods always fail (not called from a VisualForce page but from a test class, always success = false).
I find this implementation of the Site.ForgotPassword really weird and I would like to know whether I am somehow making a mistake or there is an alternative way to implement this functionality by using the Site.ForgtoPassword site.
I hope your are checking your page with salesforce url.
for example https://c.cs30.visual.force.com/apex/CommunityLogin
if you want to re-test "Site.forgotPassword(username);" method then please below URL:-
yourcommunityURL/CommunityLogin
replace "https://c.cs30.visual.force.com" with community URL. then try. It will work
Use Full link for you :-
http://amitsalesforce.blogspot.in/search/label/Community
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
thanks for your reply. Actually the ForgotPassword functionality works, the issue is that the Site.ForgotPassword(username) function always return true if called from a VF page, even if the username is not existing. If I put an existing username I correctly receive the password reset email. I would like to know whetehr it is possible to receive a warnign when the username is not exisitng. Thanks
The return value will always be true unless it’s called outside of a Visualforce page. If it's called outside of a Visualforce page, it will be false.
Please let us know if this will help you