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
gmog220448gmog220448 

Getting error while trying to update the actorid of a ProcessInstanceWorkItem record

Hi Everybody,
I have a problem while trying to update actorid of a ProcessInstanceWorkItem record through Apex.  As part of delegating to a new user, we need to reassign the request to a new user.  This update can be done by an administrator (System Administrator) or by a manager (who can be a normal user such as Default Employee profile user, etc).  The code is working for administrator users.  But throwing the below error.
   
Error in Saving the Record: Delegate_after_trig: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 04iT0000000LcnHIAS; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: [] Class.myClass.tstMethod: line 22, column 1 trigger.Delegate_after_trig: line 182, column 1
   
I thought if I can run the apex code as System Administrator, I may not come across the above error.  Hence I tried the below approaches.

  1. Set "Modify All" flag on the request, which starts the approval process.  This worked fine.  But this allowed the users to see other users details.  But we don't want this behavior.  Hence this option is ruled out.
  2. Created a class "without sharing" with only this method (as the documentation mentioned that the code in this class does not follow the logged in user's sharing rules and run as System Administrator)
  •             Called this method from another class.  But this threw the same error mentioned above.
  •             Called this method from a trigger.  But this threw the same error mentioned above.


Here is the code, which I am using to update the actorid.  I hardcoded some values for my testing. The query is working fine and returning the result what I am expecting.  I tried updating OriginalActorId by logging in as normal user, it is getting updated with out any errors.

 

I found some posts with this issue on this board, but did not have much details on what they did to make it work for them.  Hence I thought of seeking your help.  I greatly appreciate if someone can help me in resolving this error.

    
public without sharing class myClass{
    public static void tstMethod() {
        //Get Processinstance workitem
        List<ProcessInstanceWorkItem> piwi_to_update = new List<ProcessInstanceWorkItem>();
        List<ProcessInstanceWorkItem> piwi = [SELECT ActorId, OriginalActorId
                            FROM ProcessInstanceWorkitem
                               WHERE ProcessInstanceId in ('04gT000000070mUIAQ')
                             AND actorid != '00530000003eDDbAAM'];
        System.debug('piwi ----------> ' + piwi);
        for (integer j=0; j<piwi.size(); j++){
            System.debug('--------------->piwi[' + j + '] ------------> ' + piwi[j]);
            piwi[j].ActorId = '00530000001mxv2';
            //piwi[j].OriginalActorId = '005T0000001UydwIAC';
            piwi_to_update.add(piwi[j]);
        }
        //Update ProcessInstance work items
        system.debug('-------------->piwi_to_update = ' + piwi_to_update);
        update piwi_to_update;
    }
}

Starz26Starz26

At first glance:

 

1. Are you sure the user you are using for the ActorID has access to the object / sharing rights to the record to which you are assigning them as the actor?

gmog220448gmog220448

Yes.  The user (user is member of "Default Employee" profile) has the access to this object, but does not have the sharing rights (sharing rights mean "Modify All" setting on the object to this user/profile, right?).

Starz26Starz26

In order the be the "Actor" the user would need to have sharing access to the record that you are assign him/her to as the actor.

 

Check your OWD and if it is Private / Public Read, then check the Sharing settings for the current Owner Role of the record and see if it is shared with the "actorid" user role.

 

If the answer is no, then you cannot assign them as the actor.

DixitSDixitS
Got the answer to the same please help me to fig out?
mohd Waseemuddinmohd Waseemuddin
same problem, Any one able to update processinstanceworkitem->ActorId field as standard user(non admin)