Sending Automated Emails to All Related Contact Roles When an Opportunity is Won #inSalesforce

Sending Automated Emails to All Related Contact Roles When an Opportunity is Won #inSalesforce


Prerequisites: 


1.

Create an email template

Select Setup | Classic Email Templates and open it

Click New Template | For this example, select the Custom option | Click Next | Check the box for Available For User

Provide it with an Email Template Name like Closed Won Opportunity | Click Next | Paste these merge fields into the Subject field like {!Opportunity.Name} {!Opportunity.StageName}

Paste these merge fields into the HTML Body field as an example

Opportunity Name:{!Opportunity.Name}

Stage: {!Opportunity.StageName}

Close Date: {!Opportunity.CloseDate}

Amount: {!Opportunity.Amount}

Link: {!Opportunity.Link}

Next | Copy text from HTML version | Save


2.

Create Email Alert

Setup | Click New Email Alert | Select Opportunity as the Object | Select Closed Won Opportunity as the Email Template

Select Related Contact as the Recipient Type | Move Related Contact: Contact from the Available Recipients column to the Selected Recipients column | Click Save


Create Flow:

1. 

Setup | New Flow | Select Record-Triggered Flow | Click Start | Select to Trigger the Flow when A record is created or updated | Choose Object | Select Opportunity as the Object | Criteria - StageName Equals Closed Won

Set When to Run the Flow for Updated Records to Only when a record is updated to meet the condition requirements

Click Done


2. GET: Get Record | Label like curOpportunityContactRole | 

Select Opportunity Contact Role as the Object | Criteria -

OpportunityId Equals $Record Opportunity.ID | select All records | How to Store Record Data, select Choose fields and assign variables (advanced) | Click in the Field in the Select Variables to Store Opportunity Contact Role Fields section | Click + New Resource

Set Resource Type as Variable

Provide it with an API Name like colContactRole | Set the Data Type as Record | Set the Object as Opportunity Contact Role | Click the checkboxes for Available for Input, Available for Output and Allow multiple values (collection)

Click Done | In the Select Opportunity Contact Role Fields to Store in Variable, the first Field is set to ID automatically | Set the second Field to Contact Id

Click Done


3. DECISION: Add a Decision to Determine the Flows Actions

Provide it with a Label like Contact Roles? 

In the New Outcome section, provide it with a Label like Yes | Criteria - Set the Resource field to the colContactRole variable Is Null $GlobalConstant.False

For When to Execute Outcome, select If the condition requirements are met | Click Default Outcome

Provide it with a Label like No | Click Done

End Flow if No Contact Role(s) Found | Click the + icon below No | Select End


4. LOOP: Create a Loop Element to Get All Related Contacts if Contact Role(s) Found

Select Loop | Provide it with a Label like loopContactRoles 

Select colContactRole as the Collection Variable

Select First item to last item as the Direction

Click Done


5. GET: Create Get Records Element Within Loop

Select Get Records | Label like getContact as an example

Select Contact as the Object | Criteria -

Contact Id  Equals Current item from Loop>Contact Id>Contact Id | Select Only the first record for How Many Records to Store | Select Choose fields and assign variables (advanced) for How to Store Record Data

in the Select Variables to Store Contact Fields section

Set Field to Email | Click in the Variable field and click +New Resource | Select Variable as the Resource Type

Provide an API Name like varEmail | Select Text as Data Type | Check the checkboxes for Available for input and Available for output | Click Done | Click the + icon below getContact | Select Action

Search for then select Closed Won Opportunity in the Action search bar | Provide a Label like Send Email | Select Record Opportunity>Opportunity Id | Done | Save


6. Provide it with a Flow Label like Email All Contact Roles When Opportunity Closed Won | 

Click Activate and Test it


















Visual: https://www.youtube.com/watch?v=SkOvgN8TpYk

Reference: https://help.salesforce.com/s/articleView?id=000390005&type=1


Comments