Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (inv.Approval_Comment_Check__c == 'Requested')
- {
- approvalStatements.put(inv.Id, inv);
- // Reset the field value to null,
- // so that the check is not repeated,
- // next time the object is updated
- inv.Approval_Comment_Check__c = null;
- }
- for (Invoice_Statement__c invs : [SELECT (SELECT ID
- FROM ProcessInstances
- ORDER BY CreatedDate DESC
- LIMIT 1)
- FROM Invoice_Statement__c
- WHERE ID IN :approvalStatements.keySet()])
- {
- processInstanceIds.add(invs.ProcessInstances[0].Id);
- }
- // Now that we have the most recent process instances, we can check
- // the most recent process steps for comments.
- for (ProcessInstance pi : [SELECT TargetObjectId,
- (SELECT Id, StepStatus, Comments
- FROM Steps
- ORDER BY CreatedDate DESC
- LIMIT 1 )
- FROM ProcessInstance
- WHERE Id IN :processInstanceIds
- ORDER BY CreatedDate DESC])
- {
- // If no comment exists, then prevent the object from saving.
- if ((pi.Steps[0].Comments == null ||
- pi.Steps[0].Comments.trim().length() == 0))
- {
- approvalStatements.get(pi.TargetObjectId).addError(
- 'Operation Cancelled: Please provide a reason ' +
- 'for your approval / rejection!');
- }
- }
Add Comment
Please, Sign In to add comment