+1 vote
1 view
in Salesforce by (11.3k points)

I would like to change emails sent from workflows to be sent to an additional recipient, the manager of the current User. I can possibly do this by rebuilding all my workflows, but I'm wondering is there any way to do it in a Trigger on the EmailMessage object so that this will work for every email sent. I have tried to do this, but it seems that emails sent from workflows don't go through this object.

1 Answer

+1 vote
by (28.6k points)

 Instead of building a trigger you can do a search and replace in eclipse in order to add the recipient.

You'd start with this:

<alerts>

  ...

  <recipients>

    <field>Engineer_s_Email__c</field>

    <type>email</type>

  </recipients>

  <recipients>

    <recipient>[email protected]</recipient>

    <type>user</type>

  </recipients>

  ...

</alerts>

Then do a file search and replace (ctrl-h). Search for </alerts> and replace with <recipients><recipient>[email protected]</recipient><type>user</type></recipients></alerts>. Which would give you:

<alerts>

  ...

  <recipients>

    <field>Engineer_s_Email__c</field>

    <type>email</type>

  </recipients>

  <recipients>

    <recipient>[email protected]</recipient>

    <type>user</type>

  </recipients>

  ...

<recipients><recipient>[email protected]</recipient><type>user</type></recipients></alerts></alerts>

Click okay and it'll add the manager as a recipient to all the workflow email alerts.

If you want to get fancy, use a regex.

...