简体   繁体   中英

Send Salesforce Attachment with Docusign

I'm trying to use DocuSign API in Salesforce (apex code) to send an envelope with the document.

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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