+ Start a Discussion
Email ApprovalEmail Approval 

Auto approval comment in email

I have written apex class to auto approve step(except last and first step) of approval process if it is pending for more than 2 days, and I have scheduled that that apex class that runs every day and it is working fine.
Now if it got auto approved the next approval get an email that approval is pending for you. I am sending the email from approval process step only. I am setting comment of auto approval from code, comment like 'The previous step was auto approved'.
I need this comment to sent to next approval email? how to achieve    
TJ DTJ D
To achieve this you would need a VF component with a controller to handle the logic. This VF component then can be used in your VF email template. If your email template is not based on VF then you should convert it to VF.
In your controller code; use below query to get the access to the last step in the approval pocess. relatedObjectId should be passed from the VF email template-->VF component-->controller.
List<ProcessInstanceStep> steps = [SELECT Comments, ActorId, StepStatus
                                           FROM ProcessInstanceStep 
                                           WHERE ProcessInstance.TargetObjectID = :relatedObjectId
                                           ORDER BY SystemModStamp DESC LIMIT 1];
Then iterate over the list you get (basically only one record in the list) and access comments field and pass it to the VF component and then email template. 

Hope this helps.