I custom a lightning component to reassign the approval process.I use the code under to reassign the approver successfully,but I can't add comments. Here is my code:

public static String ReassignProcess(String objectId,String content1,String reassignTo){

    List<ProcessInstanceWorkItem> workItemList = [SELECT p.ProcessInstance.Status, 
    FROM ProcessInstanceWorkitem p WHERE p.ProcessInstance.TargetObjectId = :objectId];
    workItemList.get(0).ActorId  = reassignTo;
    update workItemList;
    return '3';


I don't know how to add comments,but I see the standard reassign action could send comments.I've been searching for answer for a long time and couldn't find an answer.Hope an experienced expert could give me answer here.Thank you guys!!


Because the ProcessInstanceStep object does not allow an update operation from API, you cannot use the object ProcessInstanceStep. Instead you will need to use Approval.ProcessSubmitRequest to set comments. There's an example on the this link as how to set the comments from Apex in approval process. Hopefully this approach works for your use case.

// Create an approval request for the account
Approval.ProcessSubmitRequest req1 = 
    new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');

Comments are not available on ProcessInstanceWorkItem object, you will need to use the ProcessInstanceStep object instead which represents one work item in an approval process.

You will need to fetch the ProcessInstanceStep associated with the ProcessInstanceId and the ActorId and then accordingly update the comments. I haven't tried it myself, but something as below should get you there:

ProcessInstanceStep step = 
    [SELECT Id, StepStatus, Comments 
         FROM ProcessInstanceStep 
     WHERE ActorId = :reassignTo AND ProcessInstanceId = :<the instance id> limit 1];

step.Comments = 'Your Comments';
update step;

You can refer more on this object on its documentation.

  • When I try to update step,I got an error:"operation Update not allowed on ProcessInstanceStep".Is there anyway to add comments? – J.Who Dec 10 at 2:19
  • I didn’t realize that when writing this. Will update if there’s any other way – Jayant Das Dec 10 at 2:28
  • I added a reference to an example as how you can set comments during an approval process, hopefully that helps. – Jayant Das Dec 10 at 13:52
  • I think this example is to custom submit objectId to approval process.Anyway my project manager cancel this request.^_^ – J.Who Dec 11 at 3:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.