[SalesForce] When a Task is created from a case, I would like to assign it to the case account owner

How do I assign a task that's created from a case to the case account owner? I tried using assign id in Process builder but the case account owner wasn't an option. Assigning it to Account ID didn't work because that's not set on task creation.

Best Answer

Task and Event are often difficult objects to work with using declarative tools like Workflow and Process Builder due to their polymorphic lookup relationships. You can't traverse those relationships using dot notation (WhatId.OwnerId) because they can relate to almost any object.

Stick with me here, this is going to be a long one.

To accomplish this you need to manually traverse those relationships step by step to get to the data you want, and then update the record you want to update.

There are basically two ways that you can approach this, one is a declarative option using a combination of a Process Builder and a Flow, the other is programmatically with Apex. Below I will be detailing the declarative way to do this. For any future visitors looking for an Apex solution, the solution is to do exactly what I'm doing with these flows, but via SOQL queries and Apex variables instead.

1. Create an Auto-Launched Flow (Search for 'Flow' in setup)

2. Create 4 Flow Variables (Text)

Navigate to the Manager tab and press New Resource. Select Variable as your resource type, and Text as your Data Type. Name them as follows:

  • ActivityId *mark this one "Available for input"
  • CaseId *mark this one "Available for input"
  • AccountId
  • OwnerId

enter image description here

3. Get Case Info using Case Id

After creating your variables, go back to the Elements tab, and add your first Get Records element. We'll use this to query for information from the Case, mainly we want the AccountId. Configure the element as shown in my screenshots below:

enter image description here

enter image description here

Essentially what we're doing here is asking Salesforce to lookup the Case for us, based on the Case Id, and return back the Account Id and store it in the AccountId variable. This will allow us to basically do the same thing using another Get Records element which looks up the Account.

4. Get Account Info using Account Id

Repeat the exact same process as above, only this time we're using the newly collected AccountId variable to query for the Account, and return the OwnerId into the OwnerId variable:

enter image description here

enter image description here

5. Update the Task Record With OwnerId

Now you will add an Update Record element to the flow, which we'll be using to update the Task that started this whole process. We do that by matching the Task Id to the ActivityId variable, and setting the OwnerId to the OwnerId variable:

enter image description here

6. Save and Activate this new flow

7. Create a Process Builder that runs this Flow when conditions are met

Search for "Process Builder" in Setup, create a new Process on the Task object that runs when a record changes.

Add the appropriate criteria that you want to use to trigger the process to run (Task Type = 'Support Initiated' for example), and then add an Immediate Action with the Action Type of Flows. Name it whatever you want.

In the Flow dropdown, select the flow we just created. Then, click the + sign to add two Flow Variables, and select ActivityId and CaseId which should both be available if you set them correctly in step 2. If not, go back and check again.

Set the ActivityId to a Field Reference of [Task].Id (Called Activity Id), and set the CaseId to a Field Reference of [Task].WhatId (Called Related To Id).

enter image description here

8. Save and Activate the Process Builder - Test and confirm

Related Topic