
//Class For Send Email If User forgot his Password.
public class CLS_ForgotPassword {
public string Username{get; set;}
public string email;
private String newPassword;
public ID cntctID;
public ID acctID;
public Boolean showDisplay {get; set;}
public contact user;
public cls_ForgotPassword(){
}
public PageReference submit(){
try{
user = [Select id,accountid,email,username__c,password__c from contact where username__c=:Username limit 1];
cntctID= user.id;
acctID=user.accountid;
if(User != null){
email = user.email;
newPassword =user.password__c;
try{
SendEmail();
}
catch(Exception e){
System.debug(e);
}
}
PageReference page = new PageReference('/apex/VF_ContactAuthentication');
page.setRedirect(true);
return page;
}Catch(Exception e){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Please provide valid Username.');
ApexPages.addMessage(myMsg);
return null;
}
}
public void SendEmail(){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<EmailTemplate> e = new List<EmailTemplate> ([Select Id, Name from EmailTemplate where Name = 'Forgot Password']); mail.setTemplateId(e[0].Id);
mail.setTargetObjectID(cntctID);
mail.setWhatID(acctID);
String[] toaddress = new String[]{};
toaddress.add(email);
mail.setToAddresses(toaddress);
System.debug('@@@@'+email);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
thanks advance
1 resposta
I'd recommend posting on the Developerforce boards, as there are more coding folks there who can give you advice. There is also a great Youtube video from Dreamforce this year on writing code coverage.
http://youtu.be/IzbxvoIlCb4