将DocuSign与使用APEX触发器发送的电子邮件通知一起嵌入

时间:2019-04-29 17:02:54

标签: salesforce docusignapi apex

我们目前有一个审批流程,当报价被批准为客户附件时。

APEX触发器就像

 trigger approvalQuote    on Quote(after update){
  set<Id> quoteIdsApproved= new set<Id>();
  set<Id> quoteIdsSOWupdates= new set<Id>();
  for(Quote q: trigger.new){
    quoteIdsSOWupdates.add(q.Id);
    system.debug('++++++++++++++2');
    if(q.Status!=trigger.oldMap.get(q.Id).Status && q.Status=='Approved'){
        quoteIdsApproved.add(q.Id);
    }
   }
   if(quoteIdsApproved.size()==1)
    approvalQuote_Handler.sendEmailAlert(quoteIdsApproved);
   approvalQuote_Handler.UpdateSOWStage(quoteIdsSOWupdates);
   }

在处理程序中,我们有

public class approvalQuote_Handler{
    @future

    public static void sendEmailAlert(set<id> quoteIds){
        List<Quote> QuoteLst=[Select Id,Contact.Id,Contact.Email, OwnerId From Quote  where id IN :quoteIds];
        string emailId=QuoteLst[0].Contact.Email;
        Id contactId= QuoteLst[0].ContactId;
        for(Id quoteId: quoteIds){
            List<Attachment> attachments = [SELECT Id,Name, Body, ContentType FROM Attachment WHERE ParentId = :quoteId ORDER BY CreatedDate DESC LIMIT 1];
            List<Messaging.EmailFileAttachment> email_attachments = new List<Messaging.EmailFileAttachment>();
            for(Attachment att : attachments){
                Messaging.EmailFileAttachment email_att = new Messaging.EmailFileAttachment();
                email_att.setBody(att.Body);
                email_att.setContentType(att.ContentType);
                email_att.setFileName(att.Name);
                email_att.setinline(false);
                email_attachments.add(email_att);
            }
            //generate email here like 
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            Id template_id =  [SELECT id, name 
                               FROM EmailTemplate 
                               WHERE developername =  'Quote_Template'].Id;
            string [] toAddresses=new string[1];
            toAddresses[0]=emailId;
            email.setToAddresses(toAddresses);  // Quote contact Email Id
            //email.setCcAddresses(to_cc_receivers);    //list of email addresses
            email.setTargetObjectId(contactId); //Id of Lead, User or Contact if that is target object. not required
            email.setWhatId(quoteId);           //Id of object that should do field merge
            email.settemplateid(template_id);
            email.setFileAttachments(email_attachments);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        }
    }
}

我是新的Docusign,不确定如何将Docusign嵌入到sendEmailAlert()中,以便附件允许用户对其进行签名。

0 个答案:

没有答案