• Mike F.
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hello

 

I'm having a strange issue, let me start with my code:

 

VisualForce:

 

<apex:commandButton action="{!sendEmail}" value="Send Email" id="emailButton"> <apex:param name="frmParam" assignTo="{!frm}" value="{!$User.Email}"></apex:param> <apex:param name="toParam" assignTo="{!to}" value="{!Application__c.Email__c}"></apex:param> <apex:param name="subjParam" assignTo="{!subject}" value="Your application for position no. {!Application__c.Job_Requisition__r.name}"></apex:param> </apex:commandButton>

 Controller:

 

public class emailApplicant { private Application__c app; private String jobRef = null; public string frm; public string to; public string subject; public string emailBody; public string getFrm(){ return frm; } public string getTo(){ return to; } public string getSubject(){ return subject; } public string getEmailBody(){ return emailBody; } public void setFrm(string value){ frm = value; } public void setTo(string value){ to = value; } public void setSubject(string value){ subject= value; } public void setEmailBody(string value){ emailBody=value; } public emailApplicant(ApexPages.StandardController controller){ app = (Application__c)controller.getSubject(); //Id id = System.currentPageReference().getParameters().get('id'); jobRef = [SELECT name FROM job_req__c WHERE id = :app.job_requisition__c].name; } public Application__c getAppInfo(){ return app; } public String getJobRef(){ return jobRef; } public PageReference sendEmail(){ PageReference p = new PageReference('https://na6.salesforce.com/'+app.job_requisition__c); p.setRedirect(true); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String [] toAddresses = new String[]{to}; mail.setToAddresses(toAddresses); mail.setReplyTo(frm); mail.setSenderDisplayName(frm); mail.setSubject(subject+to+frm); mail.setPlainTextBody(emailBody); Messaging.sendEmailResult[] results = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail}); for ( Messaging.sendEmailResult result : results ) { if ( !result.isSuccess () ) { System.debug ( result ); return p; } } return p; } }

 

The issue is that if I use a commandbutton in the VisualForce page I get the following error:

 

 

System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Invalid to address : null

 

This value is not null, and I can attest to this because if I simply change the commandButton into a commandLink, the result is positive. Could someone tell me if there is a bug, or if I am using the component incorrectly.

 

Thanks,

Wes