繁体   English   中英

无法发送附件-Salesforce Docusign API

[英]Unable to send attachment - Salesforce Docusign API

我正在尝试通过Apex和Docusign“ CreateAndSendEnvelope” API在机会记录中发送附件(记录中有一个附件)。

但我收到此错误“ DocuSign EnvelopeId:Exception-System.CalloutException:Web服务标注失败:WebService返回了SOAP错误:锚标记处理期间发生错误。无效的文档faultcode = soap:Client faultactor = https:// demo .docusign.net / api / 3.0 / dsapi.asmx

以下是所使用的代码。

 // Render the contract
        System.debug('Rendering the contract');
        PageReference pageRef = new PageReference('/apex/RenderContract');
        pageRef.getParameters().put('id',contract.Id);

        //Blob pdfBlob = pageRef.getContent();     
        Attachment att = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE Parentid = :contract.Id LIMIT 1];
        Blob pdfBlob = att.Body; 


        // Document
        DocuSignAPI.Document document = new DocuSignAPI.Document();
        document.ID = 1;
        document.pdfBytes = EncodingUtil.base64Encode(pdfBlob);
        document.Name = 'Contract';
        document.FileExtension = 'pdf';
        envelope.Documents = new DocuSignAPI.ArrayOfDocument();
        envelope.Documents.Document = new DocuSignAPI.Document[1];
        envelope.Documents.Document[0] = document;

        // Recipient
        System.debug('getting the contact');
        Contact contact = [SELECT email, FirstName, LastName 
            from Contact where id = :contract.CustomerSignedId];

        DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient();
        recipient.ID = 1;
        recipient.Type_x = 'Signer';
        recipient.RoutingOrder = 1;
        recipient.Email = contact.Email;
        recipient.UserName = contact.FirstName + ' ' + contact.LastName;

        // This setting seems required or you see the error:
        // "The string '' is not a valid Boolean value. 
        // at System.Xml.XmlConvert.ToBoolean(String s)" 
        recipient.RequireIDLookup = false;      

        envelope.Recipients = new DocuSignAPI.ArrayOfRecipient();
        envelope.Recipients.Recipient = new DocuSignAPI.Recipient[1];
        envelope.Recipients.Recipient[0] = recipient;

        // Tab
        DocuSignAPI.Tab tab1 = new DocuSignAPI.Tab();
        tab1.Type_x = 'SignHere';
        tab1.RecipientID = 1;
        tab1.DocumentID = 1;
        tab1.AnchorTabItem = new DocuSignAPI.AnchorTab();
        tab1.AnchorTabItem.AnchorTabString = 'By:';


        DocuSignAPI.Tab tab2 = new DocuSignAPI.Tab();
        tab2.Type_x = 'DateSigned';
        tab2.RecipientID = 1;
        tab2.DocumentID = 1;
        tab2.AnchorTabItem = new DocuSignAPI.AnchorTab();
        tab2.AnchorTabItem.AnchorTabString = 'Date Signed:';

        envelope.Tabs = new DocuSignAPI.ArrayOfTab();
        envelope.Tabs.Tab = new DocuSignAPI.Tab[2];
        envelope.Tabs.Tab[0] = tab1;        
        envelope.Tabs.Tab[1] = tab2;        

        System.debug('Calling the API');
        try {
            DocuSignAPI.EnvelopeStatus es 
            = dsApiSend.CreateAndSendEnvelope(envelope);
            envelopeId = es.EnvelopeID;
        } catch ( CalloutException e) {
            System.debug('Exception - ' + e );
            envelopeId = 'Exception - ' + e;
        }

任何想法如何克服这个错误?

谢谢。

原始海报(OP)的评论是

它在将整个记录呈现为pdf时效果很好...但是现在我尝试仅发送附件而不是整个记录..我开始收到此错误。

因此,我的猜测是信封请求存在文档问题。

最佳调试方式:查看正在发送到DocuSign平台的内容。

尝试使用beta API记录器常规记录器 然后通过编辑问题将日志添加到您的问题。

这个问题我遇到了同样的错误。 “锚标记处理期间发生错误。无效的文档faultcode = soap:Client faultactor = https://demo.docusign.net/api/3.0/dsapi.asmx

您需要将附件标签中需要签名的所需字符串替换为锚点标签字符串。

更换:

tab1.AnchorTabItem.AnchorTabString ='通过:'; tab2.AnchorTabItem.AnchorTabString ='签名日期:';

至 :

tab1.AnchorTabItem.AnchorTabString ='文档中的签名标签'; tab2.AnchorTabItem.AnchorTabString ='文档中的签名标签';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM