Create Innovative Solution

Master Salesforce App Building Start Your App Builder Journey

Merge Fields in Salesforce Tasks

Using Workflow to create followup tasks or reminders is a common use case. It is also simple to setup, just create a workflow rule with a rule trigger date a number of days in the future. Say we wanted to have a followup task generated 5 days before the Opportunity close date. This is easy, but standard workflow comes with a limitation, merge fields cannot be used for field values. This means that all of the tasks created would have the same subject and description. In this article we will look at how Process Builder can be used as an alternative, to create Task Records with merge fields.

First lets review how it would be done with Workflow. First we create the workflow rule with a time trigger 5 days before the Opportunity:Close Date.

opp-time-trigger

Then we configure the workflow task that should be created.

opp-task-creation

So, with a few minutes of work, we have our time dependent workflow setup to create a task for every Opportunity, to create a task for the Opportunity Owner, to remind them to followup as the close date of the Opportunity is approaching.

opp-time-workflow-3

Great. Job Done? Well let’s have a look at the result. As you can see below, the Tasks are created, but they all have the same subject. Although you can see what Opportunity they are related to and the Account, it would be useful to have more information in the task subject and comments about the opportunity, instead of the three tasks related to three different opportunities having the same subject and description. This limitation was recognised way back in 2008 where it was raised as an idea here: Merge Fields in Workflow Tasks

Now that Process Builder is available, there is an alternative. Let’s see how it can be used to create tasks with merge fields. Here is the view of the Process. The object is Opportunity and the process will start when a record is created or edited.

pb-choose-object

pb-flow-diagram

The scheduled action is defined to defined to execute 5 days before the Opportunity Close Date.

pb-execute-time

Now we get to the interesting part. The ability to create a Task record with Merge Fields. As you can see use the ‘Create a Record’ action and choose Task as the Record Type. We then can set any of the Task object fields with values, that can be Reference, Picklists or Formulas. To create the record and link to the related Opportunity, we must set the ‘Assigned To ID‘ field using a reference to the Opportunity Owner field. Not shown in the screenshot, but critical to linking the task to the Opportunity is setting the ‘Related To Id‘ to the Opportunity Id. If we don’t do this, the task will be created with the Opportunity Owner as the owner of the task, but not linked to the opportunity. We set the Priority and Status using the Picklist values. The subject is where we can get creative and build up a string that refers to values in the Opportunity Record. In this case the formula includes the Opportunity Type (to know whether it is New Business or Existing Busines), the Opportunity Name and the Opportunity Amount, so we have some idea of the size of the opportunity, all from the Task Subject. If there is too much to fit in the subject, we can also use the Description field.

pb-formula-create-task

Once Opportunity records are created and have a pending scheduled action, they will be visible as a Paused Flow Interview.

pb-paused-waiting-interviews

The final result, showing the tasks that have been created with merge field values from the Opportunity.

pb-merge-field-tasks

What Certification are you studying for now?

Focus on Force currently provides practice exams and study guides for sixteen certifications