fork download
  1. trigger QuoteAttachmentProcessing on Quote (after insert, after update) {
  2. Set<Id> quoteIds = new Set<Id>();
  3.  
  4. if (Trigger.isInsert || Trigger.isUpdate) {
  5. for (Quote quote : Trigger.new) {
  6. quoteIds.add(quote.Id);
  7. }
  8. }
  9.  
  10. if (!quoteIds.isEmpty()) {
  11. processQuoteAttachments(quoteIds);
  12. }
  13.  
  14.  
  15. public void processQuoteAttachments(Set<Id> quoteIds) {
  16. List<Quote> quotesToUpdate = new List<Quote>();
  17.  
  18. for (Id quoteId : quoteIds) {
  19. List<Attachment> quoteAttachments = [SELECT Id, Body FROM Attachment WHERE ParentId = :quoteId];
  20.  
  21. Boolean isAnyDocumentSigned = false;
  22.  
  23. for (Attachment attachment : quoteAttachments) {
  24. Blob attachmentBody = attachment.Body;
  25. String pdfContent = attachmentBody.toString();
  26.  
  27. // Check for initials within the PDF content
  28. Boolean hasInitials = checkForInitials(pdfContent);
  29.  
  30. if (hasInitials) {
  31. isAnyDocumentSigned = true;
  32. break;
  33. }
  34. }
  35.  
  36. // Update Quote record with overall signature status
  37. Quote quoteToUpdate = new Quote(Id = quoteId);
  38. quoteToUpdate.Signed_Status__c = isAnyDocumentSigned;
  39. quotesToUpdate.add(quoteToUpdate);
  40. }
  41.  
  42. if (!quotesToUpdate.isEmpty()) {
  43. update quotesToUpdate;
  44. }
  45. }
  46.  
  47. public Boolean checkForInitials(String pdfContent) {
  48.  
  49. Pattern initialsPattern = Pattern.compile('Initials: ([A-Za-z]{2})');
  50. Matcher matcher = initialsPattern.matcher(pdfContent);
  51.  
  52. return matcher.find();
  53. }
  54.  
  55. }
Success #stdin #stdout #stderr 0.01s 12528KB
stdin
Standard input is empty
stdout
Object: nil error: did not understand #QuoteAttachmentProcessing
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #QuoteAttachmentProcessing (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
Object: nil error: did not understand #insert
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #insert (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:10)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:42)
stderr
./prog:2: expected expression
./prog:10: expected expression
./prog:42: expected expression