Ask Search:
Katharine AndersonKatharine Anderson 

How do you send email alerts to contacts based on opportunities?

I want to set up an automated email system where salesforce emails contacts when they make closed/won opportunities.  

I tried to set up a workflow rule/email alert to do this, but when I put together the rule criteria based on the Opportunity object, the email alert cannot find an email field for the Opportunity.  All of my Opportunities have Contact Roles, and I would think that Salesforce would be able to find the emails that way, but it seems like that isn't possible.  

Given that the email field is on the contact record, I don't want to duplicate my information by putting it on the Opportunity record as well.

Any ideas?

Thanks in advance.
Best Answer chosen by Moderator (salesforce.com) 
Marco (werewolf) CasalainaMarco (werewolf) Casalaina
The contact roles table is a layer of indirection from the Opportunity table, that's why it can't find an email on it -- the contact role doesn't actually have any email on it per se, the linked contact does.

I think your best option is to make a lookup to Contact from Opportunity.  You could then copy the primary contact role to that custom field using a trigger like this (see the one marked as the solution).  Then your email alert would be able to see that contact's email address.

Note that such a trigger would not work retroactively, only for opportunities that are changed after you've set your trigger.

If this answer worked for you, please mark it as the best answer.  Thanks!

All Answers

Marco (werewolf) CasalainaMarco (werewolf) Casalaina
The contact roles table is a layer of indirection from the Opportunity table, that's why it can't find an email on it -- the contact role doesn't actually have any email on it per se, the linked contact does.

I think your best option is to make a lookup to Contact from Opportunity.  You could then copy the primary contact role to that custom field using a trigger like this (see the one marked as the solution).  Then your email alert would be able to see that contact's email address.

Note that such a trigger would not work retroactively, only for opportunities that are changed after you've set your trigger.

If this answer worked for you, please mark it as the best answer.  Thanks!
This was selected as the best answer
Bobby BoslerBobby Bosler
Werewolf, 

Forgive my ignorance, but I am also trying to do this, but am not sure where to put the code to which you are referring. Could you give some step by step pointers to a newby SF admin?

I created the custom field on the opportunity (named it PrimaryContactCopy??), but I'm not sure what to do next.