Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. trigger approvalQuote on Quote(after update){
  2. set<Id> quoteIdsApproved= new set<Id>();
  3. set<Id> quoteIdsSOWupdates= new set<Id>();
  4. for(Quote q: trigger.new){
  5. quoteIdsSOWupdates.add(q.Id);
  6. system.debug('++++++++++++++2');
  7. if(q.Status!=trigger.oldMap.get(q.Id).Status && q.Status=='Approved'){
  8. quoteIdsApproved.add(q.Id);
  9. }
  10. }
  11. if(quoteIdsApproved.size()==1)
  12. approvalQuote_Handler.sendEmailAlert(quoteIdsApproved);
  13. approvalQuote_Handler.UpdateSOWStage(quoteIdsSOWupdates);
  14. }
  15.  
  16. public class approvalQuote_Handler{
  17. @future
  18.  
  19. public static void sendEmailAlert(set<id> quoteIds){
  20. List<Quote> QuoteLst=[Select Id,Contact.Id,Contact.Email, OwnerId From Quote where id IN :quoteIds];
  21. string emailId=QuoteLst[0].Contact.Email;
  22. Id contactId= QuoteLst[0].ContactId;
  23. for(Id quoteId: quoteIds){
  24. List<Attachment> attachments = [SELECT Id,Name, Body, ContentType FROM Attachment WHERE ParentId = :quoteId ORDER BY CreatedDate DESC LIMIT 1];
  25. List<Messaging.EmailFileAttachment> email_attachments = new List<Messaging.EmailFileAttachment>();
  26. for(Attachment att : attachments){
  27. Messaging.EmailFileAttachment email_att = new Messaging.EmailFileAttachment();
  28. email_att.setBody(att.Body);
  29. email_att.setContentType(att.ContentType);
  30. email_att.setFileName(att.Name);
  31. email_att.setinline(false);
  32. email_attachments.add(email_att);
  33. }
  34. //generate email here like
  35. Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
  36. Id template_id = [SELECT id, name
  37. FROM EmailTemplate
  38. WHERE developername = 'Quote_Template'].Id;
  39. string [] toAddresses=new string[1];
  40. toAddresses[0]=emailId;
  41. email.setToAddresses(toAddresses); // Quote contact Email Id
  42. //email.setCcAddresses(to_cc_receivers); //list of email addresses
  43. email.setTargetObjectId(contactId); //Id of Lead, User or Contact if that is target object. not required
  44. email.setWhatId(quoteId); //Id of object that should do field merge
  45. email.settemplateid(template_id);
  46. email.setFileAttachments(email_attachments);
  47. Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement