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
kabkab 

Pdf attachments are not coming in the email after renderAs="pdf"

I have a visual force page VF1

Code looks loke following

<apex:page standardController="Opportunity" id="thePage" extensions="Controller1">  

<apex:form id="theForm">
        <h2><a href="../{!Opportunity.Id}">goto Opportunity : {!Opportunity.Name}</a></h2>
        <br></br><br></br>
        <apex:Commandbutton action="{!sendPdf}"  value="sendPdf"/>
   
   </apex:form>    

 

</apex:page>

 

When I remove "<h2><a href="../{!Opportunity.Id}">goto Opportunity : {!Opportunity.Name}</a></h2>" line the pdf attachment comes fine in the email({!Opportunity.Name} and {!Opportunity.ID} is causing that problem. Any workaround for this.Anyone experienced this issue?

Pl. help.

 

Controller has the following method

 

public PageReference sendPdf() {

 

PageReference pdf = Page.VF_PDF;

// add parent id to the parameters for standardcontroller

pdf.getParameters().put('id',opp.Id);

 

// 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) {

System.debug(

'***Exception:'+e);

body = Blob.valueOf(

'Error in Fax pdf');

}

 

Messaging.EmailFileAttachment attach =

newMessaging.EmailFileAttachment();

attach.setContentType('application/pdf');

attach.setFileName('Test.pdf');

attach.setInline(false);

attach.Body = body;

String emailId=opp.email__c;

Messaging.SingleEmailMessage mail =newMessaging.SingleEmailMessage();

mail.setUseSignature(false);

mail.setToAddresses(newString[] { emailId });

mail.setSubject('test');

mail.setHtmlBody('testbody');

mail.setFileAttachments(newMessaging.EmailFileAttachment[] { attach });

 

// Send the email

Messaging.sendEmail(newMessaging.SingleEmailMessage[] { mail });

 

}

returnnull;

 

}



Best Answer chosen by Admin (Salesforce Developers) 
kabkab

I used another page to redirect the page and called the pdf attachment and it worked fine.

All Answers

kabkab

I used another page to redirect the page and called the pdf attachment and it worked fine.

This was selected as the best answer
dash27dash27

kab wrote:

I used another page to redirect the page and called the pdf attachment and it worked fine.


Can you clarify what you mean?