Is it possible to create a trigger for emails sent from workflows?
I would like to change the emails sent from workflows to be sent to an additional recipient, the current user's manager. I can do this by rebuilding all my workflows, but I'm wondering if there is a way to do this in a Trigger on the EmailMessage element so that this works for every message sent. I tried to do this, but it seems that emails sent from workflows do not go through this object.
source to share
As an alternative to creating a trigger, you can search and replace in eclipse to add a recipient.
You will start with this
<alerts>
...
<recipients>
<field>Engineer_s_Email__c</field>
<type>email</type>
</recipients>
<recipients>
<recipient>jason.bourne@salesforce.com</recipient>
<type>user</type>
</recipients>
...
</alerts>
Then search and replace the file (ctrl-h). Find </alerts>
and replace with <recipients><recipient>manager.john@salesforce.com</recipient><type>user</type></recipients></alerts>
. Which will give you:
<alerts>
...
<recipients>
<field>Engineer_s_Email__c</field>
<type>email</type>
</recipients>
<recipients>
<recipient>jason.bourne@salesforce.com</recipient>
<type>user</type>
</recipients>
...
<recipients><recipient>manager.john@salesforce.com</recipient><type>user</type></recipients></alerts></alerts>
Click OK and it will add the manager as a recipient to all workflow email notifications.
If you want to get fancy, use a regular expression.
source to share
The EmailMessage is directly related to Cases; it is found in Setup | Cases | Email messages (as described in the Winter 10 Release Notes ). It is used for incoming emails (usually with the Email-to-Case feature). Because of this, I believe it is not involved in the outbound email functionality associated with Workflows.
Unfortunately, the only way I know to add an additional recipient to all workflows is to change every Workflow rule.
source to share