One common scenario that many people using both Lead Queues and Case Queues face is the pain of assigning the record to themselves. A workaround that I see many people suggesting to use (and previously have always used) was to create a JavaScript button that would do the magic for you. I’ve seen throughout the Salesforce community people seeming to run up against walls with the code not quite working. This is often because they are Admins/Declarative Developers trying to dabble in code. This blog is one that I’ve been meaning to write for a while, because it solves this problem with just using Flow. Because its a very simple Flow and a different use case than beginners typically see, it gets people realizing what they can actually do with Flow!
For this example we are going to be using the Case Object. Our goal is to create a Button that will live on the Case Page Layout. When we press that Button, we want it to grab our UserId and make us the Case Owner. This is as simple as it gets!
Lets begin by navigating to the Flow (Setup | Create | Workflows & Approvals | Flows)
Then, hit “New Flow”
Great, now lets get to the fun stuff! Lets go ahead and grab the Record Update element and drop it on our Canvas. Name your Record Update “Update Record Owner” and then search for the Case Object.
After you Select the Case Object, we need to filter it based on the CaseId. So lets select the New Variable and make our Text Variable var_CaseId. After creating this Variable it will populate in the our criteria. That’s one perk of creating these variables on the fly.
We’ve found our ‘Record’ by filtering on the var_CaseId. Now, we need to update our Case with the OwnerId being the Running User’s Id. To do this we need to create a new variable called var_UserId. This is where we will pass in the UserId of the Running User (the person who pressed the Button).
Press OK to save this Record Update. Now, we want to Set the Record Update as our Start element by selecting the green arrow in the top right.
Notice I am saving this as a Flow and not an Autolaunched Flow. It doesn’t make a difference because an Autolaunched Flow can still be launched from a Button, but I do it to let myself know this is meant to be triggered from a Button.
Now, on our Flow Detail page we can see our Unique Name (API name for the Flow) and our Flow URL. We are going to be using this in just a second to create our Button’s URL that will do all the magic!
Now, we’ve Activated our Flow and know what our URL is going to be, lets build our our Button!
First, lets navigate to the Case’s Buttons, Links, and Actions page (Setup | Customize | Cases| Buttons, Links, and Actions). From here, we will select the New Button or Link. If you are new to Buttons, take a look at my previous posts, Choosing your Button and Writing a Button’s URL.
Awesome, now lets update our Button URL. We want to select Detail Page Button for the Display Type, Display in existing window without sidebar or header for our Behavior, and URL for our Content Source.
For our URL we are simply going to pass in the CaseId and UserId, and then we want to be returned back to the Case once the Flow finishes. Notice, the UserId will be a dynamic value based on who presses the Button.
/flow/Assign_To_Me?var_CaseId={!Case.Id}&var_UserId={!$User.Id}&retURL=/{!Case.Id}
Click Save, and you are done! Now you can add the Assign to Me button to your Page Layout(s) and snipe the easy cases from your coworkers using the old school ‘Change Owner’ method.
Thanks for this tutorial, very useful. I followed the steps and it works great for me as the administrator, but my users get an “Insufficient privileges” error. What could be causing that?
LikeLike
The issue with that would typically be that your Users don’t have the permission in their Profile to Run Flows. Take a look at their Profile and add that permission, then you should be set!
LikeLike
That did it, thanks David!
LikeLike
Thank you for a great and easy to follow tutorial. Nice to learn new stuff.
I have added it to our one of our case layouts and now my users ask if Case Status could be updated as part of the assign process. I have tried adding it to URL of the detail page button but without any luck. I would really appreciate your input.
LikeLike
Hey Allan, sorry for the late response I was traveling. Yes you can do that. You will need to make that update in your Record Update. You want to find the Status field as another field to update, and then populate the Status your users would like to to be. The downfall of this is that it would be static to the button, unless you gave them a screen. Let me know if that doesn’t solve your question!
LikeLike
Thank David for this useful post.
One quick question – can you suggest any elegant method to add the ‘Assign to Me’ Custom Link to the Case Feed layout (without having to add the ‘Custom Button’ related list that means – real estate in the Service Console is veery expensive)?
Thank you,
Ido.
LikeLike
Hey David,
Question for you. I am using the lightning version of cases. When I run this button, on the refresh, it initially takes me to the salesforce classic view and then within 2-3 seconds converts back to the lighning / console view. Is there anyway to force the refresh to only load in the lighning/console view?
LikeLike
I assume you would have to adjust the redirect URL. I’ll add that to my list of things to explore. I’ve not run into that issue myself yet to where I’ve spent the time on looking into it yet.
LikeLike
Hey David,
First of, huge fan of your blog, it has helped me IMMENSELY.
Second, I have a use Case that I need help with. We use Email2Case and often get spam email or emails that users need to easily Close as Spam from the List View. I created a Flow, PB, and button that tie all together to make this happen. However, when I click the button in the List View, nothing happens, and I get no Error message.
Any help from the Flow guru would be a great help!
Thanks!
Alan Kinsley
LikeLike
Alan,
I think that I might need to do a blog post on using Flow in a List View. In the meantime, there is a fantastic blog post that details this by one of the greats, Andy Fawcett.
https://andyinthecloud.com/2015/12/12/visual-flow-with-list-view-and-related-list-buttons/
Let me know if you do have any further questions… you have to treat your Flow differently due to sending in a collection of values instead of one value, so there might be some minor refactoring.
LikeLike
Hi David
I did exactly the same way and I have a system admin role , I didn’t had the Run flow ticked in the profile which I added to my name through a permission set. But I don’t know why the ” Assign To Me” Button is not working. Its just not changing the owner to me. Any suggestion plz how to make it work. Even I tried assigned to other profile and gave Run flow permission in their custom profiles but till its not changing the owner. plz suggest , what can be the issue? Thanks
LikeLike
I would double-check the variables are all setup correctly. With a URL it is case sensitive, so if you have a difference in spelling in your URL vs the Flow it won’t match and send in the right ID. Give that a shot, and let me know if it doesn’t solve it.
LikeLike
Hello David, Thanks for your reply. I checked both and I can find a little differenc between the variables.
My URL was : /flow/Assign_To_Me?var_CaseId={!Case.Id}&var_UserId={!$User.Id}&retURL=/{!Case.Id}
and my variables was : {!var_CaseID}, so I changed it to ID and it worked.
LikeLike
Hello David, I followed the steps and the link is working but a page is opening within another page with the Header and tabs, no matter what choice i put, new page, within page without header and side bar it is behaving the same way. Any suggestion on what might be going on.
thanks,
Anthony
LikeLike
Validate your Button is Setup as “Display in Existing Window without Sidebar or Header”. If so, then you should be fine. If still having the issue after that, are you in Lightning Experience or Classic?
LikeLike
thanks. really useful. I did try to do the same but in the search layout. So I did add a button but not in the page layout but in the search layout. It does not work obviously, any idea how to do so?
LikeLike