Tasks Automation with Flow and Custom Metadata Type

Tasks Automation with Flow and Custom Metadata Type

There are various tools that allow us to create predefined-automatic Tasks. These tools are Flow Builder, Process Builder, Workflow Rule and of course - code.

I would use Flow Builder or code when the requirements are impossible or too complex for the other tools to perform.

Using Process Builder for this purpose is rather easy and intuitive. Having said that, there are a couple of drawbacks to Process Builder. The first being the need to clone the process every time you make a change (What if you wish to change the Title or the Comment of the Task?). The second drawback is that there is no standard way to easily view the details of the Tasks definitions. So, if you wish to view which Tasks you've set under the Account in a few Process Builder processes, you'll have to go process by process in order to see them.

Last but not least, there is our good old Workflow Rule. This would be my first choice for creating Tasks. For one, it is a relatively easy and intuitive way of creating Tasks. Furthermore, Task creation through Workflow Rules allows you to display the Tasks in List Views.

On the other hand, the creation of Tasks through Workflow Rules has a major drawback - Standard fields (like 'Type'), and Custom fields (Vote for the Idea posted by Keith Sadler) are not available!

In this article, I would like to run through a scenario where there is a need to create new Tasks following the creation of a new Account.

Let's join Chuck Morris, a Salesforce Admin who works at KarateKit.COM, who has just created this process without coding and with no need to download any app.

Chuck has recently received a new requirement:

  • Create automatic Tasks for every new Account
  • Initially, one Task will be created upon the Account creation. But the number of Tasks and their content might change over time
  • The following Task fields will be used: Due Date, Priority, Status, Subject, and Type. More fields might be added over time.

While jogging and thinking about the requirements, Chuck realized he needed a dynamic, and easy way of creating and modifying the Tasks. He also needed a simple way of viewing them. After giving it some thought, he knew what needed to be done.

His solution is based on Custom Metadata Type (AKA: CMT), Process Builder and Flow Builder.

Let us join Chuck while he creates the CMT:

1. Creating a Custom Metadata Type

Go to Setup | Develop | Custom Metadata Type

A. Click on the 'New Custom Metadata Type' button.

B. Provide a meaningful Label, Plural Label, and a Description and click on 'Save'

This is what the page will look like:

The Custom Metadata Type general details

C. Creating custom fields:

  • Due Date - A Number field that will be used to add or subtract the number of days from the date the Task is created. Set 0 (zero) as the default value. Example for the way this field is calculated - if you fill in "3" and the Task will be created on September 3, then the Task's Due Date field will be set to September 6.
  • Active - A checkbox field to determine whether the Task CMT is active or not. Set the 'Default Value' as 'Checked'.
  • Comments - A Text Area (Long) where you can fill in the Task comments.
  • Object Name - A required Picklist field to hold the name of the object that the Task data will be used for. Define '--None--' as the default value.
  • Priority - A Picklist field to hold the newly created Task Priority level. Define 'Normal' as the default value.
  • Record Type Id - A Text field (18) that will be used to define the Task Record Type Id (although we will not use this field in our current process, it can help us in future requirements).
  • Record Type Name - A Text field (255) which will be used to write the Task Record Type Name (although we will not use this field in our current process, it can help us in future requirements).
  • Status - A Picklist field to hold the newly created Task Status. Define 'Not Started' as the default value.
  • Subject - A required Text field (255) to hold the Subject of the newly created Task.
  • Type - A required Picklist field to hold the newly created Task Type. Define '--None--' as the default value.

The resulting CMT page will look as follows:

The Custom Metadata Type custom fields

D. Now, let's update the CMT layout as follows:

No alt text provided for this image


2. Creating a Flow Builder

Go to Setup | Create | Workflows & Approvals | Flows

A. Creating the Flow

In the 'Flows' screen, click on the 'New Flow' button:

Creating the Flow

In the 'New Flow' screen, choose the 'Autolaunched Flow' option and click on 'Create':

Choose the 'Autolaunched Flow' option

B. Create the following variables:

Record Collection Variables:

  • SOC_TaskCMT - A collection of the 'Task Creation' Custom Metadata Type 
No alt text provided for this image
  • SOC_TasksToCreate - A collection of the new Task records that will be created
No alt text provided for this image

Record Variables:

  • SO_EachTaskCMT - A Record Variable of the 'Task Creation' Custom Metadata Type
No alt text provided for this image
  • SO_NewTask - A Record Variable of the new Task (the 'Task' object)
No alt text provided for this image

Variables:

  • VarT_AccountId - The Id of the Account (don't forget to check the 'Available for input' checkbox)
No alt text provided for this image

Formulas:

  • FOR_DueDate - This formula calculates the current date + The number of days entered in the Task CMT
No alt text provided for this image






> Before we continue, click on the 'Save' button located at the top-right of the screen

The Save button of the Flow Builder



Provide the Flow with meaningful and clear information and click on 'Save':

The Custom Metadata Type main information

C. Creating a Get element

Add the 'Get Records' element to the canvas in order to look for the Task CMT

No alt text provided for this image

Set the Condition Requirements as follows:

Get Condition Requirements

At the bottom of our 'Get Records' element, define the information as follows, then click on 'Done'.

Get Task Collection
Get Task Collection Fields

Now you can connect the Start element to the Get Records element you just created:

Connect the Start element to the Get element




D. Our next step is to create a Decision element

Drag the Decision element to the canvas and define the following information:

The Desicion element details

When you're finished, click on 'Done'.

> The Decision element criteria check whether the process found matching criteria. If not, the process will stop.

Now, connect the Get Records element to the Decision element you just created:

Connect the Get element to the Decision element





E. Creating a Loop element

Drag the Loop element to the canvas and provide it with the following information:

The Loop element details

When you're finished, click on 'Done'.

Connect the Decision element to the Loop element you just created and click on the 'Done' button in the new screen that will appear:

No alt text provided for this image

The flow will look as follows:

Connect the Decision element to the Loop element








> Make sure you save your flow occasionally. Just in case...

F. Creating an Assignment element

Drag the Assignment element to the canvas and provide it with the following information:

The Assignment element details

When you're finished, click on 'Done'.

Connect the Loop element to the Assignment element you just created and then click on the 'Done' button in the new screen that will appear:

No alt text provided for this image

The flow will look as follows:

Connect the Loop element to the Assignment element







G. Creating the second Assignment element

Drag another Assignment element to the canvas and provide it with the following information:

The second Assignment element details

When you're finished, click on 'Done'.

Connect the first Assignment element to the Assignment element you just created, and then connect the second Assignment element back to the Loop element (see screenshot below):

Connect the first Assignment element to the second Assignment element and then connect the second Assignment element back to the Loop element









H. Creating the Create Records element

Drag the Create Records element to the canvas and provide it with the following information:

The Create Records element details

When you're finished, click on 'Done'.

Connect the Loop element to the Create Records element you just created - The Flow is ready:

Connect the Loop element to the Create Records element









> Make sure you click on the 'Save' button before you exit the flow

I. Activating the Flow

After saving the flow, click on the 'Back' button located at the top-right side of the screen:

Click on the 'Back' button

Now, click on 'Activate':

Activating the Flow


3. Creating a process using Process Builder

Go to Setup | Create | Workflows & Approvals | Process Builder

A. In order to create a new Process Builder process, click on the 'New' button located at the top-right of the screen:

Click on the 'New' button in order to create a new Process Builder









B. Provide the process with a meaningful name and a description, and select 'A record changes' under the 'The process starts when':

The Process Builder details

When you're done, click on 'Save'.

C. Adding an Object

In the Process Builder canvas, click on the 'Add Object'. Then, fill in 'Account' under the 'Object' option and choose the option 'only when a record is created':

Account selection in Process Builder





Click on the 'Save' button when you're done.

D. Adding the Criteria

Click on 'Add Criteria' and add the following details in the new window on the right:

  1. Provide a meaningful Criteria Name: An Account is created
  2. Under 'Criteria for Executing Actions' section, choose the 3rd option: 'No criteria-just execute the actions!'
  3. Click on 'Save'

E. Adding an Immediate Action

  1. Click on 'Add Action' under the 'Immediate Actions'.
  2. Under the 'Action Type' picklist located at the right side of the screen, choose 'Flows'.
  3. Provide a useful name under the 'Action Name'.
  4. Under 'Flow', choose the Flow we've previously created.
  5. Under 'Set Flow Variables', set as follows: VarT_AccountId > Field Reference > [Account].Id.
  6. Click on 'Save'

This is what the screen will look like after we've defined the Flow and its variable:

The Flow details

F. Activating the flow

Click on the 'Activate' button located at the top-right of the screen and then hit the 'Confirm' button in the new window

The full process will look as follows:

The Full Process View

We are done!


A few important notes:

  1. As always, many thanks to Daniela Shibi who did her best to reduce my grammar mistakes.
  2. The process will only work if the Custom Metadata Type has records with data (metadata).
  3. Make sure you test the process in your sandbox environment before deploying it to your production environment.
  4. In this example, I created a new Process Builder. Adding the process to an existing Process Builder is also a possibility.
  5. The same Flow can be used for multiple objects


Good Luck!!!

Vijay Pierce

Salesforce Platform Lead at CoalLSL

3 年

Any feelings on how this aligns or compares to Action Plans? Thanks so much for this - I have a case where Action Plans may or may not be available and this is exactly the architecture I was considering.

回复
Omri Bliech

?? Salesforce Consultant & Implementer ?? ???? ?????? ?????????? ? YouTube: SFivrit ?? Blog: SFivrit.co.il ?? Salesforce Student Group Leader (IL) ?x8 Salesforce Certifications

4 年

Great content Gidi! Keep going ??

Max Fokin

IS Development Manager @ Taboola

5 年

Wow! Really helpful! Thanks Gidi Abramovich

要查看或添加评论,请登录

Gidi Abramovich的更多文章

社区洞察

其他会员也浏览了