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
amritamrit 

How to send pdf as email attachment which is generated from visual force page?

Hi,

 

 

I want to send pdf as email attachment which is generated  from visualforce page   .I created a button called EmailReceipt .When i click that button it will automatically attach that pdf document and send to that person's mailid which we are capturing from account.How is it possible?

Thanks

AhmedPotAhmedPot

Hi,

 

 

Please Refer below code,

 

public static void send(id cpr) {

// Define the email

    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

    PageReference pdf = Page.cprpdf;

    pdf.getParameters().put('id','a0CQ0000002Ihjj');

    pdf.setRedirect(true);

 

    Blob b = pdf.getContent();

// Create the email attachment

    Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();

    efa.setFileName('attachment.pdf');

    efa.setBody(b);

    String addresses;

    email.setSubject( 'subject' );

    string[] test = new String[] {'aa@aa.com'};

    email.setToAddresses( test  );

    email.setPlainTextBody(' body' );

    email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

// Send it

    Messaging.SendEmailResult [] r =

    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

 

}

 

Thanks,

Ahmed

amritamrit

Hi

 

 

Thanks for your reply.In your code which Id ie id cpr is passing as a parameter in send method.Is it that cprpdf Id.

Gopal ZalaGopal Zala
Hello Ahmed,
i am having similar requirment ,i wan send each image chart as email attahcment .i am having one vf with multiple chart.please guide asap.
Marlo Zarate 13Marlo Zarate 13
Hi. I am having same problem. How did you managed to work this out?