You need to sign in to do that
Don't have an account?
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;
}
I used another page to redirect the page and called the pdf attachment and it worked fine.
All Answers
I used another page to redirect the page and called the pdf attachment and it worked fine.
Can you clarify what you mean?