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
pcmca_2007@yahoo.co.inpcmca_2007@yahoo.co.in 

Email Templet Sending

Hi All,

          I have created a visualforce templet and I want to send the content using this templet.Can anybody provide me

          code for Message class for sending mail with VF templet.

 

   with Regards

Prabhash mishra

MikeGillMikeGill

I would imagine you just call the visualforce page directly - I haven't tried this

 

This should get you started 

 

 

 

pdf = Page.TESTPDF;
    // add parent id to the parameters for standardcontroller
    pdf.getParameters().put('id',(String)si.id);


    // the contents of the attachment from the pdf// returns the output of the page as a PDF

    Blob b= pdf.getContent();
     
     
    Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
   
     attach.setBody(b);
    attach.setFileName('Test.pdf');
    attach.setInline(false);
  
  
    String testEmail = 'mike@cloudava.com';
 	string[] toaddress = testEmail.split(',', 0);
 

    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setUseSignature(false);
    mail.setToAddresses( toaddress );
    mail.setSubject('Your Statement');
    mail.setHtmlBody('Dear Customer,<br><br> Please find your statement attached in the email.');
    mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); 
 
    // Send the email
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
   
}

 

 Start here - Page.YourVisualForcePage

osamanosaman

EmailTemplate EmailTemp [ Select id from EmailTemplate where Name = 'YourTemplateName'];

 

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

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

mail.setTemplateId(EmailTemp.Id);

  mail.setSaveAsActivity(true);

 mail.setReplyTo('123@213.com);         

 mail.setSenderDisplayName('Sender');

mail.setWhatId('AssociateId');                   

mail.setTargetObjectId('Contact OR Lead ID');

 

Hope this helps!

Tejpal KumawatTejpal Kumawat

You should also use for the attachment with templete :-

 

<messaging:attachment renderAs=" ">

</messaging:attachment>