You need to sign in to do that
Don't have an account?
chikku
Getting Error while Preview the VFPage
Getting error to open preview with Vfpage for Pdf Attachment in Email.
VFPage
Apex
Error
VFPage
<apex:page controller="cESend" > <apex:pageBlock title="Send email example to the related conatct email of the Account:{!acc.Name}"> <p> This is the example of the vfpage</p> <h1>Related Contacts for the Account:{!acc.Name}</h1> <apex:pageBlockTable value="{!acc.Contacts}" var="c"> <apex:column headerValue="Name">{!c.Name}</apex:column> <apex:column headerValue="Email">{!c.Email}</apex:column> </apex:pageBlockTable> <br/><br/> <apex:form> <apex:outputLabel for="Subject" value="Subject">:<br/></apex:outputLabel> <apex:inputText size="80" maxlength="80" id="Subject" value="{!eSubject}" />:<br/><br/> <apex:outputLabel for="Body" value="Body">:<br/></apex:outputLabel> <apex:inputTextarea id="Body" cols="80" rows="8" value="{!eBody}"/><br/><br/> <apex:commandButton value="Send" action="{!SendEmail}" title="Send Email"/> </apex:form> </apex:pageBlock> </apex:page>
Apex
public class cESend { public PageReference SendEmail(){ Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage(); pageReference pdfExample=Page.PDFGEN; pdfExample.setRedirect(true); Blob b=pdfExample.getContent(); Messaging.EmailFileAttachment fa=new Messaging.EmailFileAttachment(); fa.setFileName('AttachmentEmailFile.pdf'); fa.setBody(b); String eAddress; if(acc.Contacts[0].email!=null){ eAddress=acc.Contacts[0].email; for(Integer i=1;i<acc.Contacts.size();i++){ if(acc.Contacts[i].email!=null){ eAddress =acc.Contacts[i].email; } } } string[] toAddress=eAddress.split(':',0); email.setSubject(eSubject); email.setPlainTextBody(eBody); email.setToAddresses(toAddress); email.setFileAttachments(new Messaging.EmailFileAttachment[] {fa}); //Now sending th email; Messaging.SendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); return null; } public Account acc{get;set;} public string eSubject{get;set;} public string eBody {get;set;} public cEsend(){ acc=[SELECT Name,(Select Name, Id,Email from Account.Contacts)from Account Where Id=:ApexPages.currentPage().getParameters().get('Id')]; eSubject=''; eBody=''; } }
Error
acc=[SELECT Name,(Select Name, Id,Email from Account.Contacts)from Account Where Id=:ApexPages.currentPage().getParameters().get('Id')];
To preview this page you need to pass a parameter Id in the URL. Pick any account copy its Id and paste it in the end of the url like this
?Id=0010o00002d6na4