1

I have created a visualforce website which allows Authenticated users to login. I have also created a Forgot Password page which utilises the default ForgotPasswordController to do all the logic however although the page redirects as expected no email is sent to the users email address as expected.

Could anyone tell me how I could resolve this?

Visualforce:

<apex:page id="forgotPassword" showHeader="false" controller="ForgotPasswordController" title="{!$Label.site.forgot_password}">
<apex:composition template="{!$Site.Template}">
<apex:define name="body">

<apex:form id="theForm">
<apex:pageMessages id="error"/>

<h2>Reset your password</h2>
<p>Forgot your password? Enter your email address below to send you a temprary password.</p>
<br/>

<div class="row">

  <div class="col-md-4 col-sm-12 col-md-offset-4">
      <div class="login-panel panel panel-default">
          <div class="panel-heading">
              <h3 class="panel-title"><strong>Forgot Password</strong></h3>
          </div>
          <div class="panel-body">
              <form role="form">
                  <fieldset>
                      <div class="form-group">
                          <label for="username">Username</label>
                          <apex:inputText required="true" styleClass="form-control" id="username" value="{!username}"/>
                      </div>
                      <!-- Change this to a button or input when using this as a form -->
                      <apex:commandButton id="submit" value="Reset Password" action="{!forgotPassword}" styleClass="btn btn-warning btn-lg btn-block" />
                  </fieldset>
              </form>
          </div>
      </div>
  </div>
</div>

</apex:form>                  
</apex:define>
</apex:composition>
</apex:page>

Apex:

/**
 * An apex page controller that exposes the site forgot password functionality
 */
public with sharing class ForgotPasswordController {
    public String username {get; set;}   

    public ForgotPasswordController() {}

    public PageReference forgotPassword() {
      boolean success = Site.forgotPassword(username);
      PageReference pr = Page.ForgotPasswordConfirm;
      pr.setRedirect(true);

      if (success) {        
        return pr;
      }
      return null;
    }
}
4
  • Can you show me you have written the email sending functionality ? Feb 17, 2015 at 9:56
  • I havent created any other classes or components for this. As I mentioned these are default classes that came out of the box. Feb 17, 2015 at 10:44
  • Is it a Portal or Community? If community is not published, it does not send any email.
    – SEuser
    Feb 17, 2015 at 12:21
  • @KaushikRay This is for Portal accounts, the codes used above are from a custom force.com website. Feb 20, 2015 at 9:37

3 Answers 3

3

Change the main method's name from forgotPassword() to some thing else some times that also creates an issue.

3
  • I've tried using resetPassword(), still no email :-( Feb 23, 2015 at 13:10
  • @Imram did this end up working? your comment says no but its marked as the answer
    – Phil B
    Apr 16, 2015 at 13:30
  • @Imran how did you solve this issue?I am facing the same problem and would be great if you could share your solution. Solution above does not work :( Jan 22, 2016 at 18:54
1

I also faced the same issue that I was not getting password reset emails, even when Site.forgotPassword() method was returning true and here is what I was doing wrong.

1) When I was opening the Forgot password VF page for previewing in Salesforce org then it was not sending the email to reset the password.

2) When I opened the same VF page in the Force.com Site / Community / Customer Portal and then reset the password then it sent me a reset password email.

May be Salesforce does not send the reset password email when you are previewing the VF page in Salesforce but when you will open the VF page in Force.com Site / Community / Customer Portal and then reset the password then it will send you a reset email if everything is fine.

0

You are using pr.setRedirect(true); which mite be nullifying the "username" you can try using the pr.setRedirect(false); which may work.

1
  • I tried this but it has not made a difference, once interesting though although setRedirect is set to false the page still goes to forgotPasswordConfirm. Feb 17, 2015 at 10:48

You must log in to answer this question.

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