Update approver’s comment as field update

I have a unique requirement.

  • I have a field called Approver Comments on a custom object.
  • I have also created an approval process on the object.
  • Now when approver approves then I want to capture approver’s comment inside the above field.

How can I do that? Any thoughts?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can access the approvers comments via the ProcessSteps relationship. It depends on exactly when you need to do this, but for example if you wanted to do it when the final approval/rejection takes place, you could do the following:

  • Add a field to the record to indicate its comments copying time – a
    checkbox that defaults to false
  • Add a final approval/rejection access that carries out a field update
    on the record to set the checkboxvalue to true
  • Create an update trigger that checks the value of the checkbox and if
    it is true, extracts the various comments and adds them to the custom
    comments field

Here’s a code snippet that extracts the comments from each step for a case identified by ‘csId’:

  List<Case> cases=[Select c.Id, (Select Id, IsPending, ProcessInstanceId, TargetObjectId, StepStatus, OriginalActorId, ActorId, RemindersSent, Comments, IsDeleted, CreatedDate, CreatedById, SystemModstamp From ProcessSteps) 
                      From Case c where id=:csId];

  if (cases.size()>0)
     Case cs=cases[0];
     String commentsStr='';
     for (ProcessInstanceHistory ps : cs.ProcessSteps)
        commentStr+='nComment from user ' + ps.ActorId + ' : ' + ps.comments;

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x