将Docusign信封与Salesforce Custom对象相关联

时间:2018-04-14 20:46:33

标签: salesforce docusignapi apex

我在DS中创建了一个模板,其中包含映射到Salesforce字段的自定义标记。通过DS提供的JS按钮示例代码使用该模板时效果很好,字段按预期显示。

我现在正尝试使用Docusign SOAPAPI自动执行该过程。创建信封时,不会填充自定义字段;甚至是签名者的领域。

以下是我的代码: -

DocusignAPI.ArrayOfRecipient1 recipients = new DocusignAPI.ArrayOfRecipient1(); 
    recipients.Recipient = new list<DocusignAPI.Recipient>();
    DocusignAPI.Recipient recipient = new DocusignAPI.Recipient();
    recipient.Email = signer_email;
    recipient.UserName = signer_name;
    recipient.ID = 1;
    recipient.Type_x = 'Signer';
    recipient.RoutingOrder = 1;
    recipients.Recipient.add(recipient);

    DocusignAPI.ArrayOfTemplateReference templateReferences = new DocusignAPI.ArrayOfTemplateReference();
    templateReferences.TemplateReference = new list<DocusignAPI.TemplateReference>();
    DocusignAPI.TemplateReference templateReference = new DocusignAPI.TemplateReference();
    TemplateReference.Template = '6bc2930f-6d46-4804-a9fc-69d1cf3ebe09';
    templateReference.TemplateLocation = 'Server';
    templateReferences.TemplateReference.add(templateReference);


    DocusignAPI.EnvelopeInformation ei = new DocusignAPI.EnvelopeInformation();
    ei.AccountId  = account_id;
    ei.Subject = 'Lorem Ipsum';
    ei.EmailBlurb = 'More text...';
    // Create an envelope and fill it in

    DocusignAPI.CustomField field = new DocusignAPI.CustomField (); 
    field.Name = 'DSFSSourceObjectId'; 
    field.Value = 'a1qW0000000vMCj';
    field.Show = 'false';
    field.CustomFieldType = 'Text';
    DocusignAPI.ArrayOfCustomField arrayOfCustomFields = new DocusignAPI.ArrayOfCustomField();
    arrayOfCustomFields.CustomField  = new list<DocusignAPI.CustomField>();
    arrayOfCustomFields.CustomField.add(field);

     ei.CustomFields = arrayOfCustomFields;

    try {
            DocusignAPI.EnvelopeStatus result = api_sender.CreateEnvelopeFromTemplates(templateReferences, recipients, ei, true);

        envelope_id = result.EnvelopeID;
        System.debug('Returned successfully, envelope_id = ' + envelope_id );
    } catch ( CalloutException e) {
        System.debug('Exception - ' + e );
        error_code = 'Problem: ' + e;
        error_message = error_code;
    }      

所有自定义标签都与我的自定义对象相关,ID在上面的CustomField中定义。

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

原来我需要将对象API名称添加到Id中。解决方案是: -

DocusignAPI.CustomField field = new DocusignAPI.CustomField (); 
    field.Name = 'DSFSSourceObjectId'; 
    field.Value = 'a1qW0000000vMCj~Property__c';
    field.Show = 'false';
    field.CustomFieldType = 'Text';