Quick-Claim a Record from a Queue by just Opening It

I'm working with a client who has a fast-paced sales operation. The sales team works in Lightning Sales Console, with a Task Queue in the left sidebar. The requirement is that sales reps should be able to claim ownership of a task simply by clicking on it in the split-view list. (This will also work in table-view list.)

The Flow

Change Task Ownership Flow


First, we need to create an autolaunched flow that takes a recordId, checks to see if the owner is a queue, and if so, reassigns the ownership to the current user if that user has the right profile. Start by setting up the recordId variable and make it available for input.

Create recordId variable, available for input

Now drag a Get Records element onto the canvas; this is where we retrieve the record matching the recordId.

Get Records element for Source Task

Next, drag a Decision element onto the canvas and configure it to check the prefix of the OwnerId on the Task record. The default behavior is labeled "No".

Is this record owned by a Queue?

If the record is owned by a queue ("Yes" outcome), it proceeds to an Assignment element, configured to reassign the OwnerId.

Assign record to {!$User.Id}

Finally, save the record with its new owner, using an Update Record element.

Save the Task with the new owner

The full flow looks like this. Save and activate the flow. Note that there is no path out of the Decision element if the record is not owned by a queue; nothing happens in that situation.

Change Task Ownership Flow

The Custom Field: the link formula

We will create a custom field on the Task record, but Tasks are atypical, as they (along with Events and Calendars) are grouped under the Activity object, so we'll need to add our custom field on the Activity object.

You need the url for the flow you just created, so go to Setup > Flows > View Details and Versions for the flow, then copy the URL. It will look something like this: /flow/Change_Task_Ownership.

Copy the URL for the flow

On the Activity object, create a custom field called Subject Link, with the Formula Return Type of Text. We'll use the formula field to create a hyperlink to the flow while displaying the value of another field on the record. In the case of Tasks, we want to use the Subject field. (If I were creating this for a Lead, I'd refer to the Name field instead of Subject.) And, BTW, we only want to run the flow if the user has a specific profile — not everyone can claim ownership of a task. This is the value of the formula:

IF( $User.ProfileId = "[profileId]",
HYPERLINK("https://yourdomain.force.com/flow/Change_Task_Ownership?recordId="&Id&"&retURL=https://yourdomain.force.com/s/detail/"&Id, Subject ),
HYPERLINK("https://yourdomain.force.com/s/detail/"&Id, Subject )
)
That's a lot to digest, so let's step through it. The first line is the IF statement where we have hardcoded the profileId for the users we want to allow to claim ownership. (It's generally a bad idea to hardcode record ids into a formula, but profileIds aren't going to change, so we'll make an exception in this case.) If the user has the right profileId, then this field becomes a hyperlink to the url for the flow, which is comprised of your domain's baseURL (shown in red) plus the url for the flow (in blue) with "?recordId=" appended (green). Then we concatenate the Id from this record followed by the return url (this is the page served up after the flow runs.) Finally, we insert the field that will be displayed for the link, in this case Subject (yellow highlight).

If the user does NOT have the right profileId, the hyperlink alternative in the last line simply displays the record.

Display the custom link field in the list-view

The final step is to go into your list view setting and add the custom link field to the columns to be displayed — in this case, replacing the Subject field. Users will have to click on this link specifically in order for the flow to run.

Implementation Notes and Extensions

In split view, clicking on the link runs the flow and opens the cached record in the main panel. Since it's a cached version of the record, it doesn't show that the ownership has changed, even though it has. 

Also, this only works where you can insert your custom field into the columns of the list-view, which you can't do for the Recently Viewed default view.

Aside from this specific implementation with queues and record ownership, you can extend these concepts to run any flow from a link; or you can apply any href link on a list-view field, using profileId or other criteria to determine the action. Please leave a comment if you find this useful, and let us know if you find other useful applications for it.




Comments