I am trying to fetch the approval comments from ProcessInstanceStep object to a custom field named "Commnets" of another object named Order. I have written the below code. but somehow unable to fetch the comments. could anyone pls suggest. Thanks in advance!!
public class ApprProcess {
public static void ProcessInst(Order [] o1) {
for(Order o2:o1) {
ProcessInstance [] op = [SELECT Id,Status,(SELECT Id,Comments
FROM Order)
FROM ProcessInstance limit 1];
for (ProcessInstance op1 : op) {
for (ProcessInstanceStep pis : op1.Steps) {
if(op1.Status == 'Approved') {
o2.Approved_Comments__c = pis.Comments;
}
}
}
}
}
}