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
Knight12@tarunKnight12@tarun 

Attachment ofVisual Force page as PDF and Emailing

Hi Everyone,

 

 Needed Help on this Issue .I have created a visual force page and trying to send it as an attachment,Its working Fine but after load functionality is needed to send the parameters so the screen shot is given as email and the data input is missing in Email. Could any one suggest.

Here is my code:- 

<apex:page controller="pfdTest">
<Apex:inputField value="{!acc.AccName__c}"/>
<apex:inputField value="{!acc.Email__c}"/>
<apex:commandButton value="Save" action="{!pdfmethod}"/>
</apex:page>

 

public pagereference save()
{
insert acc;
system.debug('-----------------------'+acc.id);
pdfmethod();
pagereference pg=new pagereference('/apex/attachmentPDF?id='+acc.id);
return null;
}
public blob body;
public PageReference pdfmethod(){


//insert acc;

PageReference ref=page.pdfTest;
ref.getParameters().put('id',(String)acc.id);
// system.debug('-------------------------------'+ref.id);

ref.setRedirect(true);
body=ref.getContentAsPDF();

Messaging.EmailFileAttachment mefa=new Messaging.EmailFileAttachment();
mefa.setContentType('application/pdf');
mefa.setFileName('Vinee.Pdf');
mefa.Body=body;

Messaging.SingleEmailMessage msem=new Messaging.SingleEmailMessage();
msem.setToAddresses(new String[] {'tarun.mopuru@gmail.com'});
msem.setSubject('Email PDF Demo');
msem.setPlainTextBody('sending pdf to email from salesforce visualforce');
msem.setFileAttachments(new Messaging.EmailFileAttachment[] {mefa});
//send email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {msem});
return null;
}

 

Thanks In Advance