[SalesForce] Forgot password page on visualforce

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;
    }
}

Best Answer

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

Related Topic