将 DocuSign API 与 Salesforce 结合使用以使用模板创建信封时出现 SOAP 错误

SOAP Fault when Using DocuSign API with Salesforce for Creating Envelope with Templates

我正在使用 Salesforce 和 DocuSign 尝试通过模板创建信封。

    DocuSignAPI.EnvelopeTemplates templates = soapService.requestTemplates(accountId, false);
    String templateId = templates.EnvelopeTemplateDefinition[0].TemplateID;

    DocuSignAPI.EnvelopeTemplate template = soapService.requestTemplate(templateId, false);

    DocuSignAPI.EnvelopeInformation envelopeInformation = new DocuSignAPI.EnvelopeInformation();
    envelopeInformation.Subject = 'XXXXXXXXXXX';
    envelopeInformation.AccountId = accountId;
    envelopeInformation.EmailBlurb = 'XXXXXXXXXXXXX';

    DocuSignAPI.TemplateReference templateReference = new DocuSignAPI.TemplateReference();
    templateReference.RoleAssignments = new DocuSignAPI.ArrayOfTemplateReferenceRoleAssignment();
    templateReference.Template = template.EnvelopeTemplateDefinition.TemplateID;
    templateReference.TemplateLocation = 'Server';

    DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient();
    recipient.ID = currentRecipientIndex + 1;
    recipient.Type_x = 'Signer';
    recipient.Email = 'XXXXXXXXXXXXXXXX';
    recipient.UserName = 'XXXXXXXXXXXXXXXXX';
    recipient.RoutingOrder = 1;

    DocuSignAPI.ArrayOfRecipient1 recipients = new DocuSignAPI.ArrayOfRecipient1();
    recipients.Recipient = new DocuSignAPI.Recipient[1];
    recipients.Recipient.add(recipient);

    DocuSignAPI.TemplateReferenceRoleAssignment trra = new DocuSignAPI.TemplateReferenceRoleAssignment();
    trra.RoleName='Stake holder';
    trra.RecipientID = recipient.ID;

    templateReference.RoleAssignments.RoleAssignment = new DocuSignAPI.TemplateReferenceRoleAssignment[1];
    templateReference.RoleAssignments.RoleAssignment.add(trra);

    DocuSignAPI.ArrayOfTemplateReference arrayOfTemplateReference = new DocuSignAPI.ArrayOfTemplateReference();
    arrayOfTemplateReference.TemplateReference = new DocuSignAPI.TemplateReference[1];
    arrayOfTemplateReference.TemplateReference.add(templateReference);

    DocuSignAPI.EnvelopeStatus status = soapService.createEnvelopeFromTemplates(arrayOfTemplateReference, recipients, envelopeInformation, true);

但是,在 运行 代码中,我收到以下错误:

Web 服务调用失败:WebService 返回 SOAP 错误:Unspecified_Error faultcode=soap:Server faultactor=https://demo.docusign.net/api/3.0/dsapi.asmx

这引用了调用 WebServiceCallout 的 DocuSignAPI。鉴于错误的含糊不清,我将不胜感激任何关于可能导致此错误的想法。

作为对此 post 的更新,我找到了错误。 Apex 的索引从 0 而不是 1 开始(与 MatLab 不同,这是导致我混淆的原因)。因为我从索引 1 开始,XML 请求在第 0 个索引处传递 'null' 值,导致错误。从 0 开始,从 XML 中删除空值,请求通过。