+ Start a Discussion

Get Comments of Approval process in trigger

Hi, All, I tried to get the comments that user entered in the approval process page, i created a trigger on my object, here is part of the code:
if (objNew.Status__c  == 'Declined') 
      ProcessInstance[] instances = [Select p.CreatedDate, p.Id, 
      (Select Comments, StepStatus From Steps where StepStatus = 'Rejected') 
      from ProcessInstance p where TargetObjectId = : objNew.Id];
      string comment = '';
      for(ProcessInstance step :instances )
       if(step.Steps.Size() > 0) // make sure it has step and the step status is 'Rejected'
      comment = step.Steps[0].Comments;

 // start create new task...
 Task t = new Task();
 t.Description = coment;
 insert t;


the newObj.Status__c is updated thru the field update in the approval action
the issue here is the comment is always blank as step.Steps.Size()  is always 0, looks like the processInstanceStep is not inserted until this trigger is finished
so how can i get the comments that user entered in the approval page
Imran MohammedImran Mohammed

Did you find the solution for getting the comments from Approval process?


Same problem for me.  Looks like the ProcessInstanceHistory does not get updated until after the field update causes the trigger to fire.


The only reason I'm even attempting this is because SF deemed it a good idea not to include proper merge fields for rejection steps!


Very frustrating...