back to blog
Send Close Notification
November 23 2021 • 30 min read

BUSINESS REQUIREMENT 

When an opportunity is CLOSED (Won or Lost), it is a good idea to keep all the stakeholders informed. It would also be beneficial to do an analysis and record lessons learnt (particularly for lost Opportunities). This information could then be used to report and glean business insights to course correct.

While closing an Opportunity additional details (like lessons learnt) are entered and then an email is sent with the details of the opportunity to a public group/ Opportunity Team Members/ Opportunity Owner via Email.

We can achieve this by using 2 flows. The first one is a screen flow, Where you will add the Fields to get additional information on how the opportunity was closed and whether or not to send an email notification to the team. (For Small opportunities, the Owner has the ability to decide whether to skip the process).

The second part of the flow is a record triggered flow where we will pull in “Get Records” Elements and loop through team members, Group Ids and user Ids to get email Ids.

  • Create a Custom field in Opportunity Object, From Setup → Object Manager → Opportunity → Create a Custom Field with checkbox data type and Label it as Send Close Communication.

PART 1: CREATING A SCREEN FLOW

From Setup → Flows → New Flow → Screen Flow → Click Next → Select Auto-Layout. 

  Creating Screen Flow involves 5 steps:

  1. Creating a Resource for Opportunity ID
  2. Add a Screen Element for input
  3. Add an Update Record Element 
  4. Add a Screen Element to display the end screen
  5. Add a Quick Action to trigger Screen Flow

1. CREATING A RESOURCE FOR OPPORTUNITY ID

  1. In the Manager Tab of the left pane, click on New Resource.

    resource

  2. Select the Variable as Resource Type from the picklist.

    variable

  3. Give the recordId as API Name 

  4. Select Text as Data Type which will present the “Available Outside the Flow” section.

  5. Check the Available for Input checkbox 

  6. Click the Done button.

    1 1

2. ADD A SCREEN ELEMENT FOR INPUT

  1. Add a Screen Element to the Flow and Label it as Enter Comment

  2. Drag and Drop a Display Text Component on the Screen. 

  3. Give the API Name as Record_Id  and enter the Text to be displayed. 

  4. Here in the Text to display we use the {!recordId} Resource as it collects the record Id from the Screen.

    2

  5. Set the Component visibility as required. 

    Note: The recordId Variable is pulled here on the screen only to pass the id through Flow and not to display the Opportunity Id.

  6. Drag a Text Field Component onto the Screen and place it below the Display Text Component as shown in the image.

  7. Label the Component as Comment and make it a required entry by checking the Require checkbox. 

    2 1

  8. Additionally you can choose to Set Component Visibility, Validate Input and Provide Help.

  9. Drag a Checkbox Component onto the Screen and place it below the Text Component. 

  10. Label the Component as Send Close Communication. Set the Default Value to {!$GlobalConstant.True} right side of the pane.

    3

  11. On the screen Properties, Click on Configure the footer and Select Hide Previous and Hide Pause radio buttons.

    4

  12. Once the footer is set, click Done.  

    5

3. ADD AN UPDATE RECORD ELEMENT 

Done on above step takes to the flow screen

  1. Click on the ‘+’ sign and add an Update Records Element. 

  2. Label the Element  as Update Comment Field and Choose Specify conditions to identify records, and set Fields individually.

  3. Select the Object as Opportunity.

    6

  4. Filter Opportunity Records using the Id Field of the Object.

  5. Use the recordId Resource created above as the Value here.

  6. Now set the Comment and Send Close Communication Fields with the Values from the Enter Comment Screen.

  7. Assign the Values, & click Done.

    7

4. ADD A SCREEN ELEMENT TO DISPLAY END SCREEN 

  1. Add a Screen Element after the Update Comments Element.

  2. Give the Screen Element an API Name as End Screen.

  3. Drag a Display Text Component to the Screen and give it an API Name of Comment_Updated. Add the Text to be displayed and format it as required.

    8

  4. Configure Header and Footer setting to Hide Header and display Footer with a Finish button on it.

  5. Click Done.

    9

  6. Click Save As and Label the Flow as ‘Comment Screen Flow’.

    10

11

5. ADD A QUICK ACTION TO TRIGGER SCREEN FLOW

  1. Setup → Object Manager → Opportunity.

  2. Select the Button, Actions and Links Option. Now add a New Action and Label it as Send Close Communication.

  3. Select the Action Type as Flow, select the Screen Flow in the next option.

  4. Label the action as Send Close Communication  and Save it.

    12

  5. In the Opportunity page layout, from Mobile & Lightning Actions at the top select  Send Close Communication and drag it to the Salesforce Mobile & Lightning Experience Actions Section and Save it.

    14

    Note:  Additionally In the Edit page of an Opportunity, we set the visibility of the Action button to display only when the stage is closed. 

    15

PART 2: CREATING A COMMENT FLOW

Creating a Comment Flow requires the following steps:

  1. Add Get Records to get Fields from various Objects.
  2. Loop through Public Group Members Collection & assign Ids to a Collection.
  3. Loop through Opportunity Team Members and add it to a Collection.
  4. Loop through User Id Collection, Get Email Addresses and add it to a Collection.
  5. Add a Decision Element to decide Closed Won or Lost.
  6. Add Action for  Closed Won and Closed Lost.
  7. Save the Flow.

SNAPSHOT OF COMMENT FLOW

comment flow

1. ADD GET RECORDS TO GET FIELDS FROM VARIOUS OBJECTS

 GET OPPORTUNITY RECORDS FOR CLOSED WON/LOST STAGE

  1. Setup → Flows → New Flow → Record Triggered Flow.

  2. In the Start Element, Select the Object as Opportunity.

  3. In the Configure Trigger section, Select A record is created or updated.

    a

  4. Set Entry Conditions as below: 

    b

  5. Under When to Run the Flow for Updated Records, Select Every time a record is updated and meets the condition requirements.

  6. Set this Option if available: Optimize the Flow for Actions and Related records.

    c

  7. Click Done.

  GET OWNER DETAILS FROM USER OBJECT

  1. Add a Get Records Element after the Start.

    get

  2. Enter the API Name of the Element as Get Owner Name.

  3. Select the User as Object and Filter the Records where ID equals the Opportunity’s OwnerId.

    d

  4. Under Sort User Records, Select Ascending order as Sort Order and Id as Sort By. 

  5. Under How Many Records to Store, Choose to store Only the first record.

  6. Under How to Store Record Data, Select Choose fields and let Salesforce do the rest.

  7. ID is selected by default, additionally select Name Field to be stored in the Variable.

    e

  8. Click Done.

 GET OPPORTUNITY TEAM MEMBER DETAILS FROM OPPORTUNITY TEAM MEMBER OBJECT

  1. Add a Get Records Element and Label it as Get Oppty Team Members.

  2. Select Opportunity Team Member as the Object. 

  3. Filter Records by OpportunityId and the equated Value should be Opportunity Id.

    Note: The Field on the left is the Opportunity ID of the Opportunity Team Member Object and the Value on right is the ID of Opportunity Object.

    f

  4. Under Sort Opportunity Team Members Records, Select Ascending order as Sort Order and UserId as Sort By.

  5. Under How Many Records to Store, Choose to store All Records.

  6. Under How to Store Record data, Select Choose Fields and let salesforce do the rest.

  7. ID is selected by default, additionally Select UserId Field to be stored in the Variable.

    g

  8. Click Done.

  GET THE ID OF PUBLIC GROUP FROM GROUP OBJECT

  1. Add a Get Records Element and Label it Get Public Group Details.

  2. Select the Group as Object. Before filtering Group Records, make sure you have a Public Group with Members in it.

  3. Next, Filter Group Records by Name equals “your public group Name”. 

    h

  4. Under Sort Group Records, Select Ascending order as Sort Order and ID as Sort By.

  5. Under How Many Records to Store, Choose to store Only the first record.

  6. Under How to Store Record Data, Select Automatically store all fields.

    i

  7. Click Done.

 GET MEMBERS OF PUBLIC GROUP FROM GROUP MEMBERS OBJECT

  1. Add a Get Records Element and Label it as Get Public Group Members.

  2. Select Group Member as the Object and Filter Group Members Records by GroupId.

  3. Equate the GroupId to the Id from the Public Group Id Get Records Element.

    j

  4. Under Sort Group Member Records, Select Ascending order as Sort Order and UserOrGroupId as Sort By.

  5. Under How Many Records to Store, Choose to Store All Records.

  6. Under How to Store Record Data, Select Choose fields and let Salesforce do the rest.

  7. ID is selected by default, additionally Select UserOrGroupId Fields to Store in Variable.

    k

  8. Click Done

2. LOOP THROUGH PUBLIC GROUP MEMBERS COLLECTION & ASSIGN IDS TO A COLLECTION

LOOP THROUGH PUBLIC GROUP MEMBERS COLLECTION

  1. Click on "+" and now add a Loop Element.

    loop

  2. Label the Loop as Assign Public Member to Team Member.

  3. Select Get Public Group Members as Collection Variable.

  4. Specify the direction as First item to last item, and Click Done.

    l

 CREATE A RESOURCE FOR USER ID COLLECTION

  1. In the Manager Tab of the left pane, click on New Resource.

    resource

  2. Select the Variable as Resource Type from the picklist.

    variable

  3. Give User_ID_Collection_Variable as API Name.

  4. Select the Text as Data Type.

  5. To make it a Collection, Check the Allow multiple Values checkbox.

    m

  6. Click Done

 ASSIGNING USER ID TO TEAM MEMBERS

  1. Inside the Loop, Add an Assignment Element.

    inside loop

  2. Label the Element as Add Public Group User Ids to Collection.

  3. Select User_ID_Collection_Variable as the Variable.

  4. Select Add as Operator and for the Value Select Current Item from Loop Assign_Public_Member_to_Team_Member and Select UserOrGroupId from list.

    n

  5. Click Done.

3. LOOP THROUGH OPPORTUNITY TEAM MEMBERS & ADD IT TO COLLECTION

LOOP THROUGH OPPORTUNITY TEAM MEMBERS

  1. Add a Loop element to the Flow.

    o

  2. Label it as Loop through Oppty Team Member.

  3. Select Get Oppty Team Members as Collection Variable.

  4. Specify the direction as First item to last item, and Click Done.

    p

 ADD OPPORTUNITY TEAM MEMBERS TO THE COLLECTION

  1. Inside the Loop, Add an Assignment Element.

    q

  2. Label the Element as Add Oppty Team Members to Collection.

  3. Select the User_ID_Collection_Variable as Variable.

  4. Select Add as the Operator.

  5. Populate the Value with User Id from Current Item from the loop Loop through Oppty Team Members.

    r

  6. Click Done.

4. LOOP THROUGH USER ID COLLECTION, GET EMAIL ADDRESSES AND ADD TO COLLECTION

LOOP THROUGH USER ID COLLECTION

  1. Add a Loop to the Flow.

    s

  2. Label it as Loop through User ID Collection.

  3. Select User_ID_Collection_Variable as Collection Variable.

  4. Specify the direction as First item to last item and Click Done.

    t

GET EMAIL OF USERS FROM USER OBJECT

  1. Inside the Loop, Add a Get Records Element.

    u

  2. Label the Element as Get EmailID from User.

  3. Select the User as Object and Filter User Records by ID.

  4. Match the Field ID with Current Item from the loop Loop_through_Oppty.

    v

  5. Under Sort User Records, Select Ascending order as Sort Order and Id as Sort By.

  6. Under How Many Records to Store, Choose to Store Only the first record.

  7. Under How to Store Record data, Select Choose Fields and let salesforce do the rest.

  8. ID is selected by default, additionally Select Email Fields to Store in a Variable.

    w

  9. Click Done.

 CREATE A COLLECTION FOR EMAIL ADDRESSES

  1. In the Manager Tab of the left pane, click on New Resource.

    resource

  2. Select the Variable as Resource Type from the picklist.

    variable

  3. Give Email_Addresses as API Name.

  4. Select Text as the Data Type.

  5. To make it a Collection, Check the Allow multiple Values checkbox.

  6. Click Done.

    x

 ADD THE EMAIL ADDRESSES TO COLLECTION

  1. Inside the Loop, Add an Assignment Element.

    y

  2. Label the Element as Collect Email Addresses.

  3. Select the Email_Addresses as the Variable and select Add as the Operator.

  4. Set the Email from the EmailID_from_User as Value, Click Done.

    z

5. ADD A DECISION ELEMENT TO DECIDE CLOSED WON/LOST 

  1. Exit the Loop, Add a Decision Element.

    a1

  2. Label the Decision Element as Won/Lost.

  3. For the First Outcome, Label the Outcome as Opportunity Closed Won.

  4. Under Condition Requirements to Execute Outcome, Add a Condition to check if the Record Stage Equals Closed Won.

    a2

  5. Set the Outcome to Execute If the condition requirements are met.

    a3

  6. Rename the Default Outcome as Opportunity Closed Lost.

    a4

6. ADD ACTION FOR EACH DECISION PATH

    ACTION WHEN STAGE IS CLOSED WON

  1. For First Outcome of Decision, Add an Action.

    a5

  2. Select the Action as Send Email.

  3. Label the Action as Send Email for Closed Won

    a6

  4. For the Body of the Email, you can create a New Resource with the Text Template as Resource Type.

    text

  5. In the Text template, you can pull the Fields that are required and also format it.

    email

  6. For the Subject of the Email, you can create Another Resource or just use the Text Opportunity Won.

  7. In the Email Addresses (Collection) Field, Select the Email_Addresses Collection Variable.

  8. Include the Rich-Text-Formatted Body and give a Value of True.

  9. Include Sender Addresses and Select the Record Owner’s Email for the Value.

    a7

  10. Click Done.

ACTION WHEN STAGE IS CLOSED LOST

  1. Follow the same steps from Action when Stage is Closed Won.

    email1

    a8

    a9

7. SAVE THE FLOW

  1. Once all the Elements have been added to the Flow, Save the Flow.

  2. Label the Flow as Comment triggered Flow and Activate the Flow.

    save

WORKING

  1. When the Send Close Communication Action Button is clicked we get a pop up.
  2. Once the comment is entered and the Next button is clicked, the comment gets updated and also the Emails are sent. 

SNAPSHOT OF EMAIL RECEIVED

111

WRAPPING IT UP 

In this blog we created a screen Flow to get comments after closing an Opportunity and a record triggered Flow to send emails to Opportunity Team Members, Public Group Members and Owners with Opportunity details when the stage is Closed Won or Lost.

Leave a Comment

Your email address will not be published

© 2024 Digital Biz Tech