Skip to main content
edited body
Source Link
Phil Hawthorn
  • 16.8k
  • 4
  • 49
  • 76

If I'm understanding the question correctly, you can generally attach attachments to email sent out via workflow using the <messaging:attachment renderAs="PDF"> in your Email Template as per the documentation you supplied.

However, the problem you're going to have is the multiplicity of the attachments you want to create, you mention wanting to create many per Opportunity but the <messaging:attachment> cannot be a child of <apex:repeat>. If you didn't mind the data for each child being on separate pages you could do something like:

<messaging:emailTemplate subject="Test" recipientType="User" relatedToType="Opportunity">

<messaging:attachment renderAs="PDF">
    <html>
        <head/>
        <body>
            <apex:repeat var="line" value="{!relatedTo.Childrens__r}">
                <div style="page-break-after:always">{!line.Name}</div>
            </apex:repeat>
        </body>
    </html>
</messaging:attachment>

<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
</messaging:emailTemplate>

Or, maybe you could actually fire the workflow alert from the Children__c object instead (this would result in multiple emails with one attachment though). Other than that, its roll your own as per the other answers I think.

If you have a finite number of children, you could always create a rollup summary on your Opportunity to count the children and do something like:

<messaging:attachment renderAs="PDF" rendered="{!relatedTo.ChildrenCount__c > 0}">
    <html>
    <head/>
    <body>
    <div style="page-break-after:always">{!relatedTo.Childrens__r[1]Childrens__r[0]}.Name}</div>
    </body>
    </html>
</messaging:attachment>

<messaging:attachment renderAs="PDF" rendered="{!relatedTo.ChildrenCount__c > 1}">
    <html>
    <head/>
    <body>
    <div style="page-break-after:always">{!relatedTo.Childrens__r[2]Childrens__r[1]}.Name}</div>
    </body>
    </html>
</messaging:attachment>

...but alas that's not very dynamic

If I'm understanding the question correctly, you can generally attach attachments to email sent out via workflow using the <messaging:attachment renderAs="PDF"> in your Email Template as per the documentation you supplied.

However, the problem you're going to have is the multiplicity of the attachments you want to create, you mention wanting to create many per Opportunity but the <messaging:attachment> cannot be a child of <apex:repeat>. If you didn't mind the data for each child being on separate pages you could do something like:

<messaging:emailTemplate subject="Test" recipientType="User" relatedToType="Opportunity">

<messaging:attachment renderAs="PDF">
    <html>
        <head/>
        <body>
            <apex:repeat var="line" value="{!relatedTo.Childrens__r}">
                <div style="page-break-after:always">{!line.Name}</div>
            </apex:repeat>
        </body>
    </html>
</messaging:attachment>

<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
</messaging:emailTemplate>

Or, maybe you could actually fire the workflow alert from the Children__c object instead (this would result in multiple emails with one attachment though). Other than that, its roll your own as per the other answers I think.

If you have a finite number of children, you could always create a rollup summary on your Opportunity to count the children and do something like:

<messaging:attachment renderAs="PDF" rendered="{!relatedTo.ChildrenCount__c > 0}">
    <html>
    <head/>
    <body>
    <div style="page-break-after:always">{!relatedTo.Childrens__r[1]}.Name}</div>
    </body>
    </html>
</messaging:attachment>

<messaging:attachment renderAs="PDF" rendered="{!relatedTo.ChildrenCount__c > 1}">
    <html>
    <head/>
    <body>
    <div style="page-break-after:always">{!relatedTo.Childrens__r[2]}.Name}</div>
    </body>
    </html>
</messaging:attachment>

...but alas that's not very dynamic

If I'm understanding the question correctly, you can generally attach attachments to email sent out via workflow using the <messaging:attachment renderAs="PDF"> in your Email Template as per the documentation you supplied.

However, the problem you're going to have is the multiplicity of the attachments you want to create, you mention wanting to create many per Opportunity but the <messaging:attachment> cannot be a child of <apex:repeat>. If you didn't mind the data for each child being on separate pages you could do something like:

<messaging:emailTemplate subject="Test" recipientType="User" relatedToType="Opportunity">

<messaging:attachment renderAs="PDF">
    <html>
        <head/>
        <body>
            <apex:repeat var="line" value="{!relatedTo.Childrens__r}">
                <div style="page-break-after:always">{!line.Name}</div>
            </apex:repeat>
        </body>
    </html>
</messaging:attachment>

<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
</messaging:emailTemplate>

Or, maybe you could actually fire the workflow alert from the Children__c object instead (this would result in multiple emails with one attachment though). Other than that, its roll your own as per the other answers I think.

If you have a finite number of children, you could always create a rollup summary on your Opportunity to count the children and do something like:

<messaging:attachment renderAs="PDF" rendered="{!relatedTo.ChildrenCount__c > 0}">
    <html>
    <head/>
    <body>
    <div style="page-break-after:always">{!relatedTo.Childrens__r[0]}.Name}</div>
    </body>
    </html>
</messaging:attachment>

<messaging:attachment renderAs="PDF" rendered="{!relatedTo.ChildrenCount__c > 1}">
    <html>
    <head/>
    <body>
    <div style="page-break-after:always">{!relatedTo.Childrens__r[1]}.Name}</div>
    </body>
    </html>
</messaging:attachment>

...but alas that's not very dynamic

added 771 characters in body
Source Link
Phil Hawthorn
  • 16.8k
  • 4
  • 49
  • 76

If I'm understanding the question correctly, you can generally attach attachments to email sent out via workflow using the <messaging:attachment renderAs="PDF"> in your Email Template as per the documentation you supplied.

However, the problem you're going to have is the multiplicity of the attachments you want to create, you mention wanting to create many per Opportunity but the <messaging:attachment> cannot be a child of <apex:repeat>. If you didn't mind the data for each child being on separate pages you could do something like:

<messaging:emailTemplate subject="Test" recipientType="User" relatedToType="Opportunity">

<messaging:attachment renderAs="PDF">
    <html>
        <head/>
        <body>
            <apex:repeat var="line" value="{!relatedTo.Childrens__r}">
                <div style="page-break-after:always">{!line.Name}</div>
            </apex:repeat>
        </body>
    </html>
</messaging:attachment>

<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
</messaging:emailTemplate>

Or, maybe you could actually fire the workflow alert from the Children__c object instead (this would result in multiple emails with one attachment though). Other than that, its roll your own as per the other answers I think.

If you have a finite number of children, you could always create a rollup summary on your Opportunity to count the children and do something like:

<messaging:attachment renderAs="PDF" rendered="{!relatedTo.ChildrenCount__c > 0}">
    <html>
    <head/>
    <body>
    <div style="page-break-after:always">{!relatedTo.Childrens__r[1]}.Name}</div>
    </body>
    </html>
</messaging:attachment>

<messaging:attachment renderAs="PDF" rendered="{!relatedTo.ChildrenCount__c > 1}">
    <html>
    <head/>
    <body>
    <div style="page-break-after:always">{!relatedTo.Childrens__r[2]}.Name}</div>
    </body>
    </html>
</messaging:attachment>

...but alas that's not very dynamic

If I'm understanding the question correctly, you can generally attach attachments to email sent out via workflow using the <messaging:attachment renderAs="PDF"> in your Email Template as per the documentation you supplied.

However, the problem you're going to have is the multiplicity of the attachments you want to create, you mention wanting to create many per Opportunity but the <messaging:attachment> cannot be a child of <apex:repeat>. If you didn't mind the data for each child being on separate pages you could do something like:

<messaging:emailTemplate subject="Test" recipientType="User" relatedToType="Opportunity">

<messaging:attachment renderAs="PDF">
    <html>
        <head/>
        <body>
            <apex:repeat var="line" value="{!relatedTo.Childrens__r}">
                <div style="page-break-after:always">{!line.Name}</div>
            </apex:repeat>
        </body>
    </html>
</messaging:attachment>

<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
</messaging:emailTemplate>

Or, maybe you could actually fire the workflow alert from the Children__c object instead (this would result in multiple emails with one attachment though). Other than that, its roll your own as per the other answers I think.

If I'm understanding the question correctly, you can generally attach attachments to email sent out via workflow using the <messaging:attachment renderAs="PDF"> in your Email Template as per the documentation you supplied.

However, the problem you're going to have is the multiplicity of the attachments you want to create, you mention wanting to create many per Opportunity but the <messaging:attachment> cannot be a child of <apex:repeat>. If you didn't mind the data for each child being on separate pages you could do something like:

<messaging:emailTemplate subject="Test" recipientType="User" relatedToType="Opportunity">

<messaging:attachment renderAs="PDF">
    <html>
        <head/>
        <body>
            <apex:repeat var="line" value="{!relatedTo.Childrens__r}">
                <div style="page-break-after:always">{!line.Name}</div>
            </apex:repeat>
        </body>
    </html>
</messaging:attachment>

<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
</messaging:emailTemplate>

Or, maybe you could actually fire the workflow alert from the Children__c object instead (this would result in multiple emails with one attachment though). Other than that, its roll your own as per the other answers I think.

If you have a finite number of children, you could always create a rollup summary on your Opportunity to count the children and do something like:

<messaging:attachment renderAs="PDF" rendered="{!relatedTo.ChildrenCount__c > 0}">
    <html>
    <head/>
    <body>
    <div style="page-break-after:always">{!relatedTo.Childrens__r[1]}.Name}</div>
    </body>
    </html>
</messaging:attachment>

<messaging:attachment renderAs="PDF" rendered="{!relatedTo.ChildrenCount__c > 1}">
    <html>
    <head/>
    <body>
    <div style="page-break-after:always">{!relatedTo.Childrens__r[2]}.Name}</div>
    </body>
    </html>
</messaging:attachment>

...but alas that's not very dynamic

Source Link
Phil Hawthorn
  • 16.8k
  • 4
  • 49
  • 76

If I'm understanding the question correctly, you can generally attach attachments to email sent out via workflow using the <messaging:attachment renderAs="PDF"> in your Email Template as per the documentation you supplied.

However, the problem you're going to have is the multiplicity of the attachments you want to create, you mention wanting to create many per Opportunity but the <messaging:attachment> cannot be a child of <apex:repeat>. If you didn't mind the data for each child being on separate pages you could do something like:

<messaging:emailTemplate subject="Test" recipientType="User" relatedToType="Opportunity">

<messaging:attachment renderAs="PDF">
    <html>
        <head/>
        <body>
            <apex:repeat var="line" value="{!relatedTo.Childrens__r}">
                <div style="page-break-after:always">{!line.Name}</div>
            </apex:repeat>
        </body>
    </html>
</messaging:attachment>

<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
</messaging:emailTemplate>

Or, maybe you could actually fire the workflow alert from the Children__c object instead (this would result in multiple emails with one attachment though). Other than that, its roll your own as per the other answers I think.