function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
code developercode developer 

How to change the actual approver in approval process using apex?

Hi,

We are approving a record using apex.

We are updating the actor id in Process InstanceWorkitem object with desired approver.
But, the record is not getting approved with actual approver.

Can we change the actual approver of the record?
bob_buzzardbob_buzzard
Can you clarify what you mean be "the record is not getting approved with the actual approver"?
code developercode developer
Say user 'A' is submitter and 'B' is the approver.

I have logged in as user 'C' and have executed this code : 

ProcessInstanceWorkitem  p = [Select p.SystemModstamp, p.ProcessInstanceId, p.OriginalActorId, p.IsDeleted, p.Id, p.CreatedDate, p.CreatedById, p.Actor.Email, p.ActorId From ProcessInstanceWorkitem p where id='04i17000000Cay7'];
p.actorid= '00517000000HfZm'; // user id of user B
update p;
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setAction('Approve');
req.setWorkitemId(p.id);
Approval.ProcessResult actResult = Approval.process(req);

But when i see the record the actual approver is user C even though I have mentioned actor as user B.

Nisha Raj 9Nisha Raj 9
Hi code developer,
Have you got any solution for above issue?