Activity Forums Salesforce® Discussions How can I send an email while using PageReference getContent() method in Salesforce?

  • Yogesh

    Member
    December 9, 2019 at 7:16 am

    Hello,

    PageReference ref = Page.PDF_DEMO;
    Blob b = ref.getContentAsPDF();

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

    Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
    efa1.setFileName('attachment_WORK.pdf');
    efa1.setBody(b);

    String addresses;
    email.setSubject( Subject +String.valueOf(DateTime.now()));
    email.setToAddresses( EmailIds );
    email.setPlainTextBody(Body);
    email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
    Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos