I'm trying to attach a file to an email templates.

This email template will be used in a workflow, so what I need is to send it everytime a condition is met in a opportunity. The file I need to attach is one of the file that is related with the opportunity, so it will be different in every email.

I just achieved to send always the same document (static). I also tried VF templates, but still is not working.

This is the code used in the VF template:

Congratulations! This is your new Visualforce Email Template

Have anyone do it before?

Thank you so much for your time.


  • How exactly VF templates are not working? – kurunve Aug 13 at 8:19
  • Is not sending the email, maybe the problem is the recipientType that can't be oppotunity. This is my code: <messaging:emailTemplate subject="prueba aval" recipientType="Contact" relatedToType="Opportunity" > <messaging:plainTextEmailBody > Congratulations! This is your new Visualforce Email Template. </messaging:plainTextEmailBody> <messaging:attachment renderAs="PDF"> <apex:repeat value="{!relatedTo.Attachments}" var="a"/> </messaging:attachment> </messaging:emailTemplate> I'm new working with email templates, so I'm a bit lost. – jorgechamorro Aug 13 at 8:31
  • Please edit your original post to include the details and code. It is very difficult to view code in a comment. – David Cheng Aug 13 at 16:09
  • Your apex:repeat should be around the messaging:attachment, not the opposite. However you can't do that because you can't put a apex:repeat as a direct child of messaging:template. Not sure if you can do this without writing apex code... – Emmanuel BRUNO Aug 14 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.