+ Start a Discussion
Brandon BoydBrandon Boyd 

How to auto assign open tasks to the user editing/closing them?

Our tasks are drawn from a common pool, I am trying to track the close rate for each user. To do that it seems I need to reassign the task to the user editing/closing it. Salesforce support indicates this is possible, but I have no idea where to get start. Anyone have any ideas how to go about this?

*We are in Salesforce classic if it matters. 
NatarajanNatarajan
trigger TaskTrigger on Task (Before Update) {
    for(Task thisTask : Trigger.New) {
        //Before Update, If Owner Id Is Not Equal To The Actual User Editing The Record, Then Update It
        if(thisTask.OwnerId != UserInfo.getUserId()) {
            thisTask.OwnerId = UserInfo.getUserId();
        }
    }
}
I hope this helps!!
 
Deepak_KumarDeepak_Kumar
Hi Brandon,
You can go through the process builder to solve this problem.

I hope it will help you.
Thanks.
Brandon BoydBrandon Boyd
Where would I place the code provided Natarjan? I am fumbling around in the process builder and apex triggers and not seeing anything that looks like the right place. 

Trying to do it through process builder alone stalls when I try to figure out how to assign a task to the user currently editing. 

Again, any help you can provide would be appreciated. I am floundering here...
NatarajanNatarajan
No Problem, I'm happy to help. 

In Classic: Set up -> Activities -> Task Triggers -> New -> Copy Paste the Code.

Now, edit and save any of the task records by logging in as different user, you should see the magic then :)

Hope this helps!!