简体   繁体   English

使用 Docusign 发送 Salesforce 附件

[英]Send Salesforce Attachment with Docusign

I'm trying to use DocuSign API in Salesforce (apex code) to send an envelope with the document.我正在尝试在 Salesforce(顶点代码)中使用 DocuSign API 来发送包含文档的信封。

It is working when using templateid that was setup in my DocuSign sandbox, but I want to use Salesforce attachment that related to the record, and I'm getting an exception使用在我的 DocuSign 沙箱中设置的 templateid 时它正在工作,但我想使用与记录相关的 Salesforce 附件,但我收到了一个例外

dfsle.DocuSignException: Unable to read content for documents: Disti1234B.pdf (001f400000za2c9AAA).

Any idea why I'm getting it?知道为什么我会得到它吗? Note that I tried using in SF both Attachment and File, but got the same error in both.请注意,我尝试在 SF 中同时使用附件和文件,但在两者中都出现了相同的错误。

Trace:
FATAL_ERROR Class.dfsle.EnvelopeAPI: line 1027, column 1

Class.dfsle.EnvelopeAPI.APIEnvelope.<init>: line 1065, column 1

Class.dfsle.EnvelopeAPI.createEnvelope: line 1155, column 1

Class.dfsle.EnvelopeAPI.createEnvelope: line 1144, column 1

Class.dfsle.EnvelopeService.sendEnvelope: line 641, column 1

Class.dfsle.EnvelopeService.sendEnvelope: line 607, column 1

Code script:代码脚本:

Id accountId = '001f400000za2c9'; // The ID of the initiating Salesforce object.

// Create an empty envelope.
dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(accountId));

//we will use a Salesforce contact record as a Recipient here
Contact myContact = [SELECT Id, Name, Email FROM Contact where Id = '003f400001Gk49f'];

//use the Recipient.fromSource method to create the Recipient
dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(
    myContact.Name, // Recipient name
    myContact.Email, // Recipient email
    null, //Optional phone number
    'Signer 1', //Role Name. Specify the exact role name from template
    new dfsle.Entity(myContact.Id)); //source object for the Recipient

//add Recipient to the Envelope
myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });

/*WITH TEMPLATE ID IT IS WORKING FINE
//myTemplateId contains the DocuSign Id of the DocuSign Template
dfsle.UUID myTemplateId = dfsle.UUID.parse('f4252788-0799-4786-bac4-7c6a3f1d37a8');

//create a new document for the Envelope
dfsle.Document myDocument = dfsle.Document.fromTemplate(
    myTemplateId, // templateId in dfsle.UUID format
    'myTemplate'); // name of the template
*/

Attachment att = [SELECT Id, Name, Body, ContentType,LastModifiedDate,BodyLength FROM Attachment WHERE Id = '00Pf400000KPKBh'];
dfsle.Document myDocument = new dfsle.Document(att.Id, 'File', 1, att.Name, 'pdf', att.BodyLength, att.LastModifiedDate, accountId);

//add document to the Envelope
myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument });

myEnvelope = dfsle.EnvelopeService.sendEnvelope(myEnvelope, true);

Still not sure why it is happened, but I was able to get it work by using the following method:仍然不确定为什么会发生这种情况,但我能够通过使用以下方法使其工作:

list<dfsle.Document> l_doc = dfsle.DocumentService.getDocuments(ContentVersion.getSObjectType(), new set<Id>{'068f400000EFNuaAAH'});

Note that according to docusign documentation it is working only with documents (File in salesforce), it is not working with Salesforce Attachment请注意,根据 docusign 文档,它仅适用于文档(Salesforce 中的文件),不适用于 Salesforce 附件

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

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