back to blog
Notify Task Owners when Opportunity is Closed using a Flow
December 01 2021 • 10 min read

Business Challenge

When an opportunity is closed, the related Tasks are left open. This results in supply chain, engineers and others will be working on their tasks even though the opportunity has been closed.

This can be resolved by creating a Record Triggered Flow which would Update the Related Tasks status to Completed and also send notification to the task owners as soon as the Opportunity is Closed

Steps to achieve the requirement 

  1. Create custom Notification
  2. Create Flow

Create Custom Notification

  1. From the home page, click on the Gear Icon at the top and then click on Setup.

    tcn 1

  2. From the Quick Find search and select Custom Notification → Click New.

    tcn 2

  3. Enter Custom Notification Name as Task Update Notification →Under Supported Channels Check on the Desktop and Mobile checkboxes → Click Save.

    tcn 3

Create Flow

  1. From the Quick Find search and select Flows → Click New Flow.

    tcn 4

  2. Select Record Trigger Flow → Click Create.

    tcn 5

  3. Select Opportunity as the Object → Under Configure Trigger, for Trigger the flow when  option Choose A Record is Updated.

    tcn 6

  4. Under Set Entry Conditions, for Condition Requirements choose Any Condition is Met (OR) → Select Stage Name as Field, Equals as Operator and Closed Won as Value → Add Condition and make it as  Stage Name Equals Closed Lost.

    tcn 7

  5. Under When to Run the Flow for Updated Records Select Only when a record is updated to meet the condition requirements → For Optimize the flow for option Select Actions and Related Records.

    tcn 8

  6. Click Done.

  7. Make sure the Layout is Auto Layout.

    tcn 9

  8. Click (+) Icon under the start element → Select Update Records Element.

    tcn 10

  9. Enter Label as Update Task Records → Under How to Find Records to Update and Set their Values select Specify Conditions to identify records, and Set fields individually → Select Task as the Object.

    tcn 11

  10. Under Filter Task Records, for Condition Requirements to Update Records option choose All Conditions Are Met(AND). Add Filter Condition as WhatId Equals  Record > Opportunity ID.

    tcn 13

  11. Under Set Field Values for the Task Records choose Description as Field and Enter Opportunity related to this Task is Closed as the Value →  Click Add Field.

    tcn 14

  12. Choose Status as Field and Select Completed as the value.

    tcn 15

  13. Click Done.

  14. Click (+) icon → Select Get Records Element.

    tcn 16

  15. Enter Label as Get Custom Notification → Select Custom Notification Type as Object.

    tcn 17

  16. Under Condition Requirements  choose All Conditions Are Met (AND). Choose Developer Name as Field , Equals as Operator, Enter Task_Update_Notification(API name) as Value → select Ascending as Sort Order → Choose Id for Sort By.

    tcn 18

  17. For How many Records to Store Select Only the first record → For How to Store Record Data select Automatically Store all fields.

    tcn 19

  18. Click Done.

  19. Click (+) icon Under Get Custom Notification element → Click Get Records Element.

    tcn 20

  20. Enter Label as Get Task → Select Task as the Object.

    tcn 21

  21. Under Filter Task Records choose All Conditions Are Met (AND) Choose WhatID as Field, Equals as Operator and Record > Opportunity ID as Value. Under Sort Task Records, select Ascending as Sort Order and Id for Sort By.

    tcn 22

  22. Select All records under How many records to store → Select Automatically Store all fields under How to store record Data → Click Done.

    tcn 23

  23. Click (+) icon under Get Tasks element → Select Loop Element.

    tcn 24

  24. Enter Label as Loop Task Records → Select Tasks from Get_Task.

    tcn 25

  25. Under Specify Direction for Iterating Over Collection Select First Item to Last Item as the Direction.

    tcn 26

  26. Click Done.

  27. Click (+) icon.

    tcn 27

  28.  Select Assignment Element.

    tcn 28

  29. Enter Label as  Owner ID Collection → Create New Resource as a Variable.

  30. Select Variable as Resource type → Enter OwnerID as API Name → Select Text as Data Type → Check the Allow Multiple values (Collection).

    tcn 29

  31. Click Done.

  32. Select Add as Operator.

  33. Select Current Item from Loop Loop_Task_Records > .OwnerId.

    tcn 30

  34. .Click Done.

  35. Click (+) icon under Owner Id Collection element → Select Action Element.

    tcn 31

  36. Enter Custom in the search Actions box → Select Send custom Notification.

    tcn 32

  37. Enter Label as Task Close Notification→ Select Custom Notification Type Id from Get_Custom_Notification > Id.

    tcn 33

     

  38. For the  Notification Body create a New Resource.

    tcn 34

  39. Select Resource Type as Text Template → Enter API Name as Notification_Body.

    tcn 35

  40. Change the View as Rich Text to View as Plain Text → Copy the below content and Paste inside the Body. 

Hi {!Looping_Task_Records.Owner:User.FirstName} {!Looping_Task_Records.Owner:User.LastName},

The Task "{!Looping_Task_Records.Subject} " is closed and Respective Opportunity is completed.

Regards,

{!$Record.Owner.FirstName} {!$Record.Owner.LastName}

(In Task record there is no full name that is the reason here First Name and Last Name are used)

tcn 36

  1. Enter Task Close Notification text as the Value for Notification Title→ Add Recipient IDs as  OwnerId (Collection Variable).

    tcn 37

  2. Include Target ID → Select {!$Record.Id} (Opportunity Id). 

    tcn 38

  3. Click Done.

  4. Click Save at the top right corner.

    tcn 39

  5. Enter Flow Name as Update Tasks and Send Notifications → Click Save.

  6. Activate the Flow.

Testing the Flow

I picked one Opportunity record Grand Hotel Generator Installation (Opportunity stage is not Closed). This opportunity has 2 Upcoming Tasks

tcn 40

Once the opportunity stage is changed to Closed Won / Closed Lost the respected Task status updated to completed, Description field is updated and Notification is sent to Task Owners. 

tcn 41

Like the below Image It will send Notification to the Task Owner.

tcn 42

It also updates Task Status and Comment (Description). Please refer the below screenshot.

tcn 43

WRAPPING IT UP

In this Blog we have covered how to update the related Tasks statuses, update the Comments for status Change and send Notifications to the Task Owners using a Record Trigger Flow.

Leave a Comment

Your email address will not be published

© 2024 Digital Biz Tech