我正在尝试进行DocuSign和SF集成。目前,我有一个自定义按钮,用于创建文档并将其发送给收件人。效果很好,但现在我要附加分配的文档。因此,我尝试正确配置DocuSign连接到SalesForce的连接,并创建一个对象并设置要附加文档的对象。但是,即使分配了文档,我的SF对象也没有任何附件。
这是我的课程,负责将我的文档发送给我的收件人:
public with sharing class SendToDocuSignController {
private final Contract contract;
public String envelopeId {get;set;}
private String accountId = 'MYACCOUNTID';
private String userId = 'MYUSERID';
private String password = 'MYPASS';
private String integratorsKey = 'MYKEY';
private String webServiceUrl
= 'https://demo.docusign.net/api/3.0/dsapi.asmx';
public SendToDocuSignController(ApexPages.StandardController controller)
{
this.contract = [select Id, CustomerSignedId, AccountId, ContractNumber
from Contract where id = :ApexPages.currentPage().getParameters().get('id')];
envelopeId = 'Not sent yet';
SendNow();
}
public void SendNow()
{
DocuSignAPI.APIServiceSoap dsApiSend
= new DocuSignAPI.APIServiceSoap();
dsApiSend.endpoint_x = webServiceUrl;
//Set Authentication
String auth = '<DocuSignCredentials><Username>'+ userId
+'</Username><Password>' + password
+ '</Password><IntegratorKey>' + integratorsKey
+ '</IntegratorKey></DocuSignCredentials>';
System.debug('Setting authentication to: ' + auth);
dsApiSend.inputHttpHeaders_x = new Map<String, String>();
dsApiSend.inputHttpHeaders_x.put('X-DocuSign-Authentication',
auth);
DocuSignAPI.Envelope envelope = new DocuSignAPI.Envelope();
envelope.Subject = 'Please Sign this Contract: '
+ contract.ContractNumber;
envelope.EmailBlurb = 'This is my new eSignature service,'+
' it allows me to get your signoff without having to fax, ' +
'scan, retype, refile and wait forever';
envelope.AccountId = accountId;
// Render the contract
System.debug('Rendering the contract');
PageReference pageRef = new PageReference('/apex/RenderContract');
pageRef.getParameters().put('id',contract.Id);
Blob pdfBlob = pageRef.getContent();
// 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 = 'email';
recipient.UserName = 'Teste';
// 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;
}
基本上,通过此控制器,我渲染对象数据pdf并将其附加到新的DocuSign文档,然后通过API将其发送到DocuSign。之后,当收件人分配我的文档时,会在我的DocuSign连接日志中触发一个事件,但是我的对象没有关联的附件。
我遵循了this文档来配置我的Connect对象
我的DocuSign配置:
This is my Connect object configuration
This is my Connect SF configuration
如果需要其他信息,请告诉我。
谢谢。