function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chikkuchikku 

Getting Error while Preview the VFPage

Getting error to open preview with Vfpage for Pdf Attachment in Email.

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

User-added image



 
Prabu MahalingamPrabu Mahalingam
In your constructor you have a query that queries account that matches the Id passed in the parameter.

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