Creating a work flow email alert. Would like to send out to customers email found in opportunity under contact roles. Currently, the only options are to select from drop down recipient type. Is there a way to do this by selecting "role" or would custom coding need to be written?
The Opportunity Contacts aren't available for Workflow Rules, BUT you could create a flow send an email to each contact that is listed in the roles and have it record as an activity on the Opp (Email Alerts do not have tracking visibility). If that might work for you, depending on the criteria for the email to be sent I would try the following:
Create a flow with the following:
- sObject variable (var) for the Opporutnity (ref as: thisOpp) sObject
- Collection var for the Opportunity Contact Role records OppContacts
- sObject var for the Contact record we are emailing Contact2Email
- sObject Collection for the emailed contacts EmailedContacts Text
- Template for the EMail Body (this can have formatting), EmailBody
- Text Template for Email Subject, EmailSubject
- Text Template for Fault Email, FaultEmail
- Text Template for Fault Subject, FaultSubject
Creating the flow
- Create a Loop Record to lookup the opportunity that has the Contacts associated with it that we need to contact. I will reference this variable as thisOpp. On the Record Lookup, select the field values of the Opp that you will want to reference in your flow or templates, at a minimum you need the Id
- Now lookup the OpportunityContactRole record where the Opp Id = thisOpp and add them to the OppContacts sObject Colleciton with the OppId, ContactId, and any fields necessary
- Use the decision element to decide whether or not there are OppContacts in our collection
- If there are, go to a Loop, where you will be looping through the OppContacts to create a Contact2Email sObject
- Now lookup the contacts that have the Id = the Contact2Email's ContactId
- When emailing a collection, only 5 people can be emailed at a time. Now seeing as there is no limit on the # of Contact roles I would use the Send Email here, emailingh individual contacts using "Send Email". Use the text template EMailBody for the body and EmailSubject for the Subject
- Add an Assignment element to assign the contact that was in the email to a Collection called EmailedContact
- Then connect back to the Loop to complete the circle and loop through & email the other records
- Before saving and exiting your flow, make sure you create a "Send Email" and connect all of your lookup elements to it with the text templates FaultEmail and FaultSubject so if a fault occurs, you are notified
- In setup under workflow rules go to process Start the Process on the opp to only go through the process 1x
- Set your criteria for what on an Opp qualifies for the email send
- For your action, launch the flow you just made
and there you go, although I have not had the chance to test, this might at least get you started on options to email the Opportunity Contact Role Contacts with workflow. I made a mockup for you in my dev org to give you a visual of my idea.
Unless OpportunityContactRole shows up for you, which is something I've never seen, the answer would be no. Roles generally refer to User. Instead, I'd expect to see what you're looking for under Related Contacts.
I don't have access to a production org right now with Opportunities in it to check for you, but that's where what you're looking for should be. Otherwise, you'd have to specify a specific Email Address which is obviously not what you want.