Send document with merge fields filled in using Apex – Docusign

  Kiến thức lập trình

I need to be able to send a document using Apex for signature. I can get it sent but I can’t get the merge fields to populate.

I’ve tried various options which I’ve found while searching how to do it. Any help would be great please.

dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(
          myContact.Name,
          myContact.Email,
          null,
          'Signer',
          new dfsle.Entity(myOpportunityId)
      );

      String templateName = [SELECT dfsle__EmailSubject__c FROM dfsle__EnvelopeConfiguration__c WHERE dfsle__DocuSignId__c =: templateId LIMIT 1].dfsle__EmailSubject__c;

      dfsle.UUID myTemplateId = dfsle.UUID.parse(templateId);

      dfsle.Document myDocument = dfsle.Document.fromTemplate(
          myTemplateId,
          templateName
      );

      String objectString = (String) myOpportunityId + '~Opportunity';

      //create custom field
      dfsle.CustomField myCustomField1 = new dfsle.CustomField(
          'text', //type
          '##SFOpportunity', //##SF+Salesforce API name of the object                                                    
          objectString, //Id of the record         
          null,
          true,
          true);

      dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(myOpportunityId));

      //Add documents to the Envelope:
      myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument })
      .withCustomFields(new List < dfsle.CustomField > {
        myCustomField1
      });

I tried the code above, I have also try the object string without ~ and a few other things. I have got the document sending but none of the fields are filled in.

LEAVE A COMMENT