Flow – Create Task With Reminder

In this post I describe how I created a Salesforce Visual Workflow to create a new Task object which can optionally specify the date and time of the reminder value.

The Scenario

Let me start by putting this in context.  It’s a common customisation is to add a couple of extra fields to the page for the Opportunity to capture the next step and next step date.  This makes it easy for the sales person to manage the progression of the deal, and for anyone to see at a glance where the opportunity is right now.

Of course, Salesforce already has a feature set to help manage to-do lists and meetings, which it stores as Tasks and Events.  Tasks can be used as reminders for things which need to be done in the future, and they come with all the functionality needed to pop-up reminders and sync with things like Outlook and mobile device calendars.

It would be very useful then, if a new task was created every time the next step information was updated so that we can combine the clarity and convenience of the capture fields with the power of a task to pop up a reminder and track that it gets done.

When the field “Next Step Date” is updated and saved, a new task is auto created with the same date as the relevant next step date.
The subject of the task is set to the same as the next step field.
The reminder is set to 10:00am for the next step date.
The status is set to “In Progress”.

This change request came to me as part of some work that I was doing on the opportunity process.  Given that it had been hanging around for a while I thought that I would take it on and knock it out in double quick time.

Not so easy as it turns out.  Looking at the change request I could see that it had been logged some time ago but not been delivered.  Why could this be?

My first stop was to look at the classic Salesforce Workflow which is quick and easy to setup and provides the ability to create a task when a field value is updated.  But, the task which is created doesn’t have the option to set the reminder date reminder.  This is not a new problem as this post on the Idea Exchange shows: https://success.salesforce.com/ideaView?id=08730000000BphDAAS

If classic workflow techniques aren’t going to work, what about the new Process Builder workflow.  Surely all the excitement surrounding the recent arrival of the feature means that it can do everything and make you a sandwich when it’s done?!  Not quite.  There is no built in support for “create a task” in Process Builder.  I found that the closest I could get was to use a Global Action to create a new Task record.  Guess what though, no ability to specify that a reminder is needed for the task.  Process Builder would let me create a new record in the Activity object and set the fields need, but the reuse for this was zero.  Each Process, even each branch in the Process would need the fields selected and defined each time.  I did not find that option very appealing.

That leaves two programming options for delivering this feature, use Visual Workflow (a.k.a Flow) or Apex code.  Until recently only the latter would have been suitable because the processing needed to detect the field change when the record was updated.  Now that the feature knows as Trigger Ready Flows has been added by Salesforce it is possible to create Flows which can be launched from classic workflow and Process Builder, the only condition is that the Flow doesn’t include use user interface components.  This was my solution, let’s take a look at how it’s was done.

The Solution

After a long description of why I needed to build this Flow, the steps needed to make it happen are very brief.  In Flow terms, it’s just one step.


Those of you familiar will Flow may well be asking yourselves why I would bother writing a blog post for something so trivial then?  Well, there is still a twist in our tale and it has to do with the format of the reminder date.

I added input variables for the reminder to my Flow as follows:

  • Reminder Date (Date)
  • ReminderTimeHours (Number, scale 0)
  • ReminderTimeMinutes (Number, scale 0)

I added the other input variables needed for the creation of the task:

  • ActivityDate (Date)
  • IsReminderSet (Boolean)
  • OwnerId (Text)
  • Priority (Text)
  • Status (Text)
  • Subject (Text)
  • WhatId (Text)
  • WhoId (Text)

Creating the task record will provide a value for the Id of the new record, and we will need a variable to store that.  I made this be an output variable in order to make it available to the user of the Flow if they need it.

  • TaskId (Text)

With the variables all created it is a simple task to map the inputs and output to the parameters of the record create in the Flow.


The only field on the list that I haven’t described is the CalculatedReminderDateTime which is used to set when the reminder is due.  We have the values we need to to set the value, but they are not yet in the right format.

The reminder date and time is stored as a single field using the DateTime data type.  I wanted my solution to make it as easy as possible to specify the reminder details when calling the Flow.  Not many fields in day-to-day Salesforce make use of the DateTime data type, simple date fields are more common.  I didn’t want to have to convert the formats outside of the Flow, and decided that it would be best to separate the date and time components into separate fields which were passed to my flow and then deal with the DateTime data type there.

The requirement stated that the reminder should be set at 10AM on the date that the task is due.  This defines the values which will be placed to the Flow in this example as:

    • Reminder Date = 11-01-2015
    • ReminderTimeHours = 10
    • ReminderTimeMinutes = 00

Within the Flow we need to format the DateTime for these values as “2015-01-11 10:00”

Visual Workflow provides the ability to define formula fields which we can use to easily construct the DateTime value.


The formula is shown below and just put the parts together in the right order, and then returns a DateTime value:

DATETIMEVALUE(TEXT(YEAR({!ReminderDate})) & “-” & TEXT(MONTH({!ReminderDate}))& “-” & TEXT(DAY({!ReminderDate})) & ” ” & TEXT({!ReminderTimeHours}) & “:” & TEXT({!ReminderTimeMinutes}) & “:00”)

The formula field its self is specified as a DateTime, and this field can then be mapped to the ReminderDateTime of the new Task.

That’s it! Don’t forget to mark the single flow element as the start of the flow.  When you save the Flow it will warn you that there is only one step, it does not cause  problem to the operation of the flow.

Using The Flow

The new Flow can be called from a Flow Trigger or from the new Process Builder, which is what I used.  I actually needed two processes, one to process when the Opportunity is created and one for when the Opportunity is updated.  In both scenarios the Flow is called and the values from the Opportunity are used to create the task.


One comment

  1. SutoCom · January 20, 2015

    Reblogged this on SutoCom Solutions.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s