Guest User

Untitled

a guest
Feb 17th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. if (inv.Approval_Comment_Check__c == 'Requested')
  2. {
  3. approvalStatements.put(inv.Id, inv);
  4. // Reset the field value to null,
  5. // so that the check is not repeated,
  6. // next time the object is updated
  7. inv.Approval_Comment_Check__c = null;
  8. }
  9.  
  10. for (Invoice_Statement__c invs : [SELECT (SELECT ID
  11. FROM ProcessInstances
  12. ORDER BY CreatedDate DESC
  13. LIMIT 1)
  14. FROM Invoice_Statement__c
  15. WHERE ID IN :approvalStatements.keySet()])
  16. {
  17. processInstanceIds.add(invs.ProcessInstances[0].Id);
  18. }
  19.  
  20. // Now that we have the most recent process instances, we can check
  21. // the most recent process steps for comments.
  22. for (ProcessInstance pi : [SELECT TargetObjectId,
  23. (SELECT Id, StepStatus, Comments
  24. FROM Steps
  25. ORDER BY CreatedDate DESC
  26. LIMIT 1 )
  27. FROM ProcessInstance
  28. WHERE Id IN :processInstanceIds
  29. ORDER BY CreatedDate DESC])
  30. {
  31. // If no comment exists, then prevent the object from saving.
  32. if ((pi.Steps[0].Comments == null ||
  33. pi.Steps[0].Comments.trim().length() == 0))
  34. {
  35. approvalStatements.get(pi.TargetObjectId).addError(
  36. 'Operation Cancelled: Please provide a reason ' +
  37. 'for your approval / rejection!');
  38. }
  39. }
Add Comment
Please, Sign In to add comment