You need to sign in to do that
Don't have an account?
rohitash yadav 8
Passing variable from visualforce page to apex class
Hi,
I am passing a parameter email from visual force pagfe to apex class. Based on the parameter I want to send pdf to the email address, but it is displaying error
Visualforce Page:
Apex class is:
When I click on send email then it is displaying the following error:
SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: null: [toAddresses, null]
Can anyone help me:
Thanks,
Rohitash
I am passing a parameter email from visual force pagfe to apex class. Based on the parameter I want to send pdf to the email address, but it is displaying error
Visualforce Page:
<apex:page standardController="Payment_Receipt__c" extensions="ReceiptEmailController"> <apex:form > <apex:pageMessages /> <apex:pageBlock title="Send Email"> <div> <p style="text-align:center; font-size:16px;">Send an Email to <b><apex:outputField id="emailNew" value="{!Payment_Receipt__c.Contact_Email__c}" /></b> attaching Customer Details as PDF</p> </div> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:outputLabel value="Cc:" /> <apex:inputText value="{!email_cc}" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton value="Send Email" action="{!sendEmailReceipt}" rendered="true" reRender=""> </apex:commandButton> </apex:pageBlockButtons> </apex:pageBlock> <apex:iframe src="/apex/SendEmailReceiptPdf?id={!$CurrentPage.parameters.id}"/> </apex:form> </apex:page>
Apex class is:
public with sharing class ReceiptEmailController { public ID receiptId {get;set;} public String email {get;set;} public String emailNew {get;set;} public String email_cc {get;set;} public ReceiptEmailController (ApexPages.StandardController controller) { receiptId = System.currentPageReference().getParameters().get('id'); } public PageReference sendEmailReceipt() { String emailNew = System.currentPagereference().getParameters().get('emailNew'); if(email_cc !='' && !Pattern.matches('[a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}', email_cc)) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Check your email')); } else { PageReference pdf = Page.SendEmailReceiptPdf; // add parent id to the parameters for standardcontroller pdf.getParameters().put('id',receiptId); // the contents of the attachment from the pdf Blob body; try { // returns the output of the page as a PDF body = pdf.getContent(); // need to pass unit test -- current bug } catch (VisualforceException e) { body = Blob.valueOf('Some Text'); } //email = System.currentPageReference().getParameters().get('email'); Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment(); attach.setContentType('application/pdf'); attach.setFileName('receipt.pdf'); attach.setInline(false); attach.Body = body; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setUseSignature(false); mail.setToAddresses(new String[] { emailNew }); mail.setSubject('PDF Receipt Demo'); mail.setHtmlBody('Here is the email you requested! Check the attachment!'); mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); // Send the email Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with PDF sent to '+emailNew )); } return null; } }
When I click on send email then it is displaying the following error:
SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: null: [toAddresses, null]
Can anyone help me:
Thanks,
Rohitash
You have just specified the Id of the component. Since the value is not getting passed, you are getting this exception.
Also, I can see that you have useed an outputField, means the value is already there on the controller, you are not inputting the value anywhere, then what value are you trying to send from VF page to Apex?
I am trying to get the value of output field in apex class.
<apex:outputField id="emailNew" value="{!Payment_Receipt__c.Contact_Email__c}" />
What should I do to get it
Thanks,
Rohitash
I am getting the same error message.
SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: null: [toAddresses, null]
Thanks,
Rohitash
Can you share your code here?
Visualforce Page is:
APex Class is: