I want to pull all approval/rejection process comments to put in my customized report. However my code didn`t work like that way. This code only capture a comment before a final approval. For example if I have 4 persons to approve/reject a application, this code only capture comment from 3rd person. May I know how to fix this code?
trigger pullCommentsApproval on Return_Shipment__c (before update) {
if(trigger.isUpdate){
List<Return_Shipment__c> opptyList = [Select id,
(Select Id,
IsPending,
ProcessInstanceId,
TargetObjectId,
StepStatus,
OriginalActorId,
ActorId,
RemindersSent,
Comments,
IsDeleted,
CreatedDate,
CreatedById,
SystemModstamp
FROM ProcessSteps
ORDER BY CreatedDate DESC)
From Return_Shipment__c
WHERE Id IN : Trigger.new];
if(opptyList.size() > 0){
for(Return_Shipment__c opp : opptyList){
for(Return_Shipment__c opp1 : Trigger.new) {
//check copy comment is true
if(opp.id == opp1.id && opp1.Final_Approved__c) {
if (opp.ProcessSteps.size() > 0) {
opp1.Approver_Comments__c = opp.ProcessSteps[0].Comments;
//opp1.Final_Approved__c = false;
}
}
}
}
}
}
}