- February 27, 2024
- WSM
- 0 Comments
- 144 Views
- 0 Likes
- Admin, Flows
Sending Automated Emails to All Related Contact Roles When an Opportunity is Won
For users who would like for all of the Contact Roles to be automatically emailed after a related Opportunity is Closed Won, this can be accomplished by creating a Record-Triggered Flow. If users forget to add a Contact Role, this Flow will not send any emails and still allow the Opportunity to be closed.
Resolution
Pre-Work: Create Classic Email Template
- Click the gear icon on the top right corner of the Salesforce screen
- Select Setup
- In the Quick Find box, search for 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 as an example
- Click Next
- Paste these merge fields into the Subject field as an example
- {!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}
- Opportunity Name:{!Opportunity.Name}
- Click Next
- Click Copy text from HTML version
- Click Save
Pre-Work: Create Email Alert
- In the Quick Find box in Setup, search for Email Alert and open it
- Click New Email Alert
- Provide it with a Description like Email Alert for Closed Won Opportunity Flow as an example
- 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 a New Flow
- In the Quick Find box in Setup, search for Flows and open it
- Click New Flow
- Select Record-Triggered Flow and click Next
- Click Auto-Layout
Tell the Flow When to Start
- Click Start so a box appears
- Click Edit to the right of Trigger
- Select to Trigger the Flow when A record is created or updated
- Select to Run the Flow After the record is Saved
- Click Done
- Click +Choose Object
- Select Opportunity as the Object
- Set the Condition Requirements to All Conditions Are Met (AND)
- Set the Field to StageName
- Set Operator to Equals
- Set Value to 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
Get the Contact Role ID Information From the Opportunity
- Click the + icon between Start and End
- Select Get Record
- Provide a Label like curOpportunityContactRole as an example
- Select Opportunity Contact Role as the Object
- Set the Condition Requirements to All Conditions Are Met (AND)
- Set the Field to OpportunityId
- Set Operator to Equals
- Set Value to $Record Opportunity.ID
- Set the Sort Order to Not Sorted
- For How Many Records to Store, select All records
- For 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 as an example
- 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
Add a Decision to Determine the Flows Actions
- Click the + icon under curOpportunityContactRole
- Select Decision
- Provide it with a Label like Contact Roles? as an example
- In the New Outcome section, provide it with a Label like Yes as an example
- Set the Condition Requirements to Execute Outcome to All Conditions Are Met (AND)
- Set the Resource field to the colContactRole variable you just created
- Set the Operator to Is Null
- Set the Value to $GlobalConstant.False
- For When to Execute Outcome, select If the condition requirements are met
- Click Default Outcome
- Provide it with a Label like No as an example
- Click Done
End Flow if No Contact Role(s) Found
- Click the + icon below No
- Select End
Create a Loop Element to Get All Related Contacts if Contact Role(s) Found
- Click the + icon below Yes
- Select Loop
- Provide it with a Label like loopContactRoles as an example
- Select colContactRole as the Collection Variable
- Select First item to last item as the Direction
- Click Done
Create Get Records Element Within Loop
- Click the + icon below For Each
- Select Get Records
- Provide it with a Label like getContact as an example
- Select Contact as the Object
- For the Condition Requirements, select All Conditions Are Met (AND)
- Set Field to Contact Id
- Set Operator to Equals
- Set Value to Current item from Loop>Contact Id>Contact Id
- Select Not Sorted as the Sort Order
- 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 as an example
- Select Text as Data Type
- Check the checkboxes for Available for input and Available for output
- Click Done
- Click Done
Tell the Flow to Send Email to The Contact in The Loop
- 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 as an example
- Select Record Opportunity>Opportunity Id
- Click Done
- Click Save
- Provide it with a Flow Label like Email All Contact Roles When Opportunity Closed Won
- Click Activate
Resource: Knowledge Article Number 000390005
Leave a Comment