FSC - How to set the Action Plan on Tasks using two Flows

action plans flow fsc salesforce Jan 01, 2024
FSC Action Plans How to set Action Plan on Task

Set Action Plan on Tasks from Action Plan Items

Made by Elise Pottinger with Scribe

Problem to solve: When an Action Plan is launched, users don't know which Action Plan their assigned Tasks are related to. Solution: Create two flows to set a custom Action Plan lookup field on the Task with each Task's Action Plan Id.



1. Navigate to Salesforce Setup to create a custom lookup field called "Action Plan" on the Task.

2. Click "Object Manager"

3. Navigate to the "Activity" object.

4. Click "Fields & Relationships"

5. Click "New" button to create a custom field.

6. Choose "Lookup Relationship"

7. Click "Next" button.

8. Click the "Related To" dropdown and select the "Action Plan" object.

9. Click "Next" button.

10. Set the "*Field Label" as Action Plan and tab down to automatically set the Field Name.

11. Write help text to explain the purpose of the new field and how it is populated.

12. Click "Next" button.

13. Set the field level security and click the "Next" button.

14. Set the field on applicable page layout(s).

15. Go to the Home tab in Setup and search for Flow.

16. Click "Flow" to navigate to Flow.

17. Click "New Flow"

18. Create a new Autolaunched Flow.

19. Toggle open the Toolbox.

20. Click "New Resource"

21. Select Variable as the Resource Type.

22. Click the "*API Name" field and type "PassedInActionPlanId"

23. Set the "Data Type" as Record.

24. Set Availability Outside the Flow as "Available for input"

25. Click the "*Object" field.

26. Choose "ActionPlan"

27. Click "Done"

28. Create a new element in the flow.

29. Choose "Get Records"

30. Write a label such as "GetActionPlanItems" and click the Object field

31. Choose "ActionPlanItem"

32. Click "Field".

33. Click "ActionPlanId"

34. Click the "Value" field.

35. Click "PassedInActionPlanId" under Record (Single) Variable

36. Choose "Id" for the Action Plan Id

37. Choose "All Records" to create a collection and make sure "Automatically store all fields" is set.

38. Click "Save"

39. Click the "*Flow Label" field.

40. Set the flow label as something like "Set Action Plan on Task"

41. Click the "Description" field.

42. Write something along the lines of "When an action plan is created, set the Action Plan lookup field on the Tasks created from the Action Plan Items."

43. Click "Save"

44. Create a new element.

45. Click "Loop"

46. Set Label as "Loop Through Action Plan Items to Get Tasks Ids".

Set Description as "Loop through Action Plan Items to get each record's Task Id and store in a text variable".

47. Click "Collection Variable"

48. Set the Collection Variable as the "Record Collection Variable" of "Action Plan Items from GetActionPlanItems"

49. Click "Done"

50. Create a new Assignment Element after the loop.

51. Choose "Assignment"

52. Set the "Label" as something like "Assign Task Ids to Text Collection"

53. Set the "Description" as something like "Store the task Ids in a new text collection variable."

54. Click the "Variable" field.

55. Click "New Resource"

56. Select the Resource Type of "Variable"

57. Select "Variable"

58. Set the "*API Name" field as something like "VarTextTaskIDs"

59. Set the Data Type as Text.

60. Select "Text"

61. Check the box for "Allow multiple values (collection)"

62. Click "Done"

63. Set the Operator to "Add"

64. Click the "Value" field.

65. Select the "Current Item from Loop Loop_Through_Action_Plan_Items_to_Get_Task_Ids.ItemId"

(Obviously, the above works if you use the same naming convention I did.)

{!Loop_Through_Action_Plan_Items_to_Get_Task_Ids.ItemId}

66. Choose "ItemId".

NOTE - the "Id" field in the screen below is referring to the Action Plan Item record's Id.

The "ItemId" field is referring to the polymorphic text field on the Action Plan Item object that stores either the Task or the Document Checklist Item created from the Action Plan Item.

67. Click "Done"

68. Click "Save"

69. Create a new element "After Last"

70. Create a second "Loop"

71. Set the Label as "Loop Through Task Collection"

72. Click the "*Collection Variable" field.

73. Select the "VarTextTaskIDs" text collection created in the above loop.

74. Click "Done"

75. Create a new Element.

76. Choose the "Update Records" element type.

77. Set the Label as "Set Action Plan Lookup Field on Task"

78. Under "How to Find Records to Update and Set Their Values", select "Specify conditions to identify records, and set fields individually".

79. Click "Object"

80. Choose "Task"

81. Click the "Field" field.

82. Choose the "Id" field

83. Leave the Operator field as "Equals."

Click the "Value" field.

84. Under Variables, choose "Current Item from Loop Loop_Through_Task_Collection"

It will look like: {!Loop_Through_Task_Collection}

85. Under "Set Field Values for the Task Records" section, click "Field"

86. Choose the "Action Plan" field (the custom lookup field we created in the beginning of this tutorial).

87. Click the "Value" field.

88. Choose the "Record (Single) Variable of the "ActionPlan" Id from the "PassedInActionPlanId" that we are passing in from another flow (which we will create next.)

89. It should look like this:

[[PassedInActionPlanId > Action Plan ID]]

90. Click "Save"

91. Let's run through an initial test to see if it works. In order to do this, make sure you have a published Action Plan Template and a test record (such as an account or opportunity) to create it from.

Open another tab and create an Action Plan from your test record and this will set the new Action Plan record in your recent items list.

Click "Debug" in the Flow.

92. Click the "PassedInActionPlanId" field.

93. Choose your recent Action Plan record.

94. Click "Run"

95. Let's see if our flow was able to get the Action Plan's related items.

Open the dropdown beside the "Get Records" item in the Debug Details list.

96. This shows us that the Get Records successfully found the Action Plan Items.

97. Under the "Loop" debug item, we see the Action Plan Items record ids related to the Action Plan record we used.

98. Under the "Assignment" debug item, note that the Task for the current Action Plan Item was captured and assigned to the TextTaskIds variable.

99. Scrolling down in the debug list, let's open one of the "Update Records" items.

100. This shows us that the current task id in the loop is being updated so that the "Action Plan" lookup field is set with the Action Plan Id passed in at the beginning of the flow.

101. Now that we feel good that our flow works as expected, we can click "Edit Flow"

102. Click "Activate"

103. Click the back button in the Flow screen so we can create our 2nd flow.

104. Click "New Flow"

105. Choose "Record-Triggered Flow"

106. Click "Create"

107. Click the "*Object" field.

108. Choose "ActionPlan"

109. No condition requirements are needed, so leave them as "None"

110. Click "Save"

111. Click the "*Flow Label" field and write "Action Plan is Created and Launch Subflow"

112. Set the Description as "When an Action Plan is created, launch the Subflow that sets the Action Plan on Tasks by passing in the Action Plan Id."

Save the flow.

113. Create a new element.

114. Choose "Subflow"

115. Click the "Referenced Flow" field.

116. Choose the other flow we created. "Set_Action_Plan_on_Task"

117. Click the "Label" field and type "Pass Action Plan Id"

118. Toggle on "Don't Include"

119. Under "Set Input Values", set the "PassedInActionPlanId" field.

120. Choose the record that is triggering the flow, which is an "ActionPlan" object record.

121. Remove the period after the word Record. Put your cursor after the d and backspace.

122. Click "Done"

123. Click "Save"

124. Click "Activate"

125. Now, we test the whole process from the user perspective.

Go to a test record, like an Account or an Opportunity. In my example, we'll choose an Opportunity because I have an active published Action Plan Template on the opportunity object.

126. Click on your test record.

127. Click on the record's "Action Plans" related list.

128. Create a new action plan record.

129. Enter the necessary field values.

130. Set the "Action Plan Template" field.

131. Save the new action plan record.

132. Click on your new action plan record.

133. Scroll down to the action plan's related tasks.

134. Open a task record and validate that the "Action Plan" field is populated with the Action Plan record.

 

 

Subscribe toĀ get new tutorials sent to your inbox.