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
kladizkovkladizkov 

On-the-fly attachments in workflow email alert

Hi

 

I'm trying to develop a workflow rule, that can send email alert. But I need to attach a file  from "Notes and attachments" section of an object to the email. This attachment will be different for each email I send. So, storing it in email template won't work. 

 

Is there anyway to add an attachment on the fly? Please help.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

According to my research, you can do the following:

- Have the workflow rule perform a field update instead of an email alert. The field update will trigger your trigger, and you send the email from there (i.e. if (record.triggered__c ) { ... } ).

Unfortunately, there is a messaging:attachment tag in Visualforce templates, but it doesn't support adding actual files-- you can only render a new attachment (i.e. a list of cases in PDF format).

Given what you're trying to do, I'd recommend a field update with a trigger. That should get you where you want to go.

All Answers

jkucerajkucera

You might be able to use a trigger to change the template as triggers fire before workflow rules. 

 

I'm pretty sure you can't edit the workflow rules themselves though as SFDC doesn't allow production to leverage the metadata API to create workflow rules as it could be problematic.

kladizkovkladizkov

Hi,

 

From what I understand about triggers, its not possible to use it on a workflow rule. My workflow rule has a time dependent workflow action which sends an email alert after x days. What I need to do is attach a file from "notes and attachment" section to the email alert that I send. Is this possible in salesforce?

jkucerajkucera

I'm not suggesting you use the trigger to modify the workflow rule as that isn't possible from production.

 

Instead I'm suggesting you try using the trigger to modify the email template, which I believe you can do.
sfdcfoxsfdcfox

According to my research, you can do the following:

- Have the workflow rule perform a field update instead of an email alert. The field update will trigger your trigger, and you send the email from there (i.e. if (record.triggered__c ) { ... } ).

Unfortunately, there is a messaging:attachment tag in Visualforce templates, but it doesn't support adding actual files-- you can only render a new attachment (i.e. a list of cases in PDF format).

Given what you're trying to do, I'd recommend a field update with a trigger. That should get you where you want to go.

This was selected as the best answer