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
Bernd NawrathBernd Nawrath 

Email trigger for Visualforce-Component

Hello dear community, I have a PDF as a visualforce-component and I want this to be sent automatically as an attachment by a trigger when a new account is added. Any advices ?

Thanks in advance ! :)
kiranmutturukiranmutturu

Create your Email template as a Visualforce template, only rendering the relevant content for your attachment, for example:

 
<messaging:emailTemplate subject="Invoice - {!relatedTo.Name}" recipientType="Contact" relatedToType="Invoice__c">
    <messaging:attachment renderAs="pdf" filename="{!relatedTo.Name} rendered="{!relatedTo.Template__c == 'Email Template 1'}">  
        <c:MyVFForTemplate1/>    
    </messaging:attachment>
  
    <messaging:htmlEmailBody >
        Dear Customer,

        Here is your Invoice.  Please pay now, or else!
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

1. create a picklist on account and update that field from trigger 
2. create a workflow and add the email alert as action by selecting the email template 
activate the same and update the picklist values relavant to the action...

This is just a high level idea which I didn't tested... But this approach should work.