[SalesForce] Approval Process – how to get the value of the approval comment while in the parent object’s trigger

I have a field update that runs in an Approval Process as an action of Approving one of the steps.

When that field update runs, the after-update triggers are invoked.

How can I get the value of the approval comment in that after-update trigger context? I do not want to get it via @future, I need it in the trigger.

If you query the ProcessInstanceStep at the time of this trigger's execution, you will not get the current step, but only the previous one.

Best Answer

So, not a pretty solution, but it works.

1) Make a field update from the approval process to the parent object, making sure it causes a re-evaluation of workflows (there is a checkbox on the field update setup).

2) Create a workflow off of the field update in step #1, with another field update, flagging the record as being in the second round of updates. This will cause triggers to execute twice, with the second round being after the Approval Comments are committed to the DB, allowing you to get them in a query.

3) In the before-update trigger on the parent object, detect that you are in the second round of updates, and do what you need with the approval comments.

Shame on you SF for making us do stuff like this..

Solution details are here: http://christopheralunlewis.blogspot.in/2012/10/making-all-approval-comments-mandatory.html

Related Topic