Find your content:

Search form

You are here

Update approver's comment as field update

 
Share

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?


Attribution to: doga

Possible Suggestion/Solution #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;
     }
  }

Attribution to: Bob Buzzard
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3850

My Block Status

My Block Content