3

I want to reassign a queue assigned to an approval request using apex. How can i achieve this,

I have tried updating processInstanceWorkItem object but it was throwing insufficient access error

1 Answer 1

3

To change the responsible for an approval request you have to update the ActorId field on the ProcessInstanceWorkItem object with the Id of the user you want to be the actual approver.

I just did this myself in a test org:

ProcessInstanceWorkItem pi = [SELECT Id, ActorId FROM ProcessInstanceWorkItem LIMIT 1];
pi.ActorId = '0051I0000027LCVQA2';
update pi;

And it worked just fine. I even got a message stating that the request was reassigned:

reassignment

Of course, I executed that snippet with an administrator user, so if you are trying to do this in, say, a trigger called by a non-admin user, you might want to take a look in the sharing keyword. What you got might be an error due to the privileges for that non-admin user.

2
  • This approach works as a system admin or an approver for that particular record but not as anyone
    – david raj
    Jun 25, 2018 at 11:33
  • Exactly. You won't be able to modify this record unless you have the permission to do so. Hence why I mentioned that you might want to run this update in System Mode instead (ignoring user permissions). Jun 25, 2018 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .