You need to sign in to do that
Don't have an account?
Feng
the newObj.Status__c is updated thru the field update in the approval action
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:
Code:
if (objNew.Status__c == 'Declined') && trigger.IsAfter) { 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
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...