0

I send in the opportunity id into mySourceId into the routine and run through what should be the standard Docusign APEX API routines. We have a button that completes this merge using the standard Docusign routines, but are trying to get around all the extra button clicks the users are having to endure.

I have a template that is created and available on Docusign with Salesforce related Custom Field tags on the document. Is there something from the documentation that I'm missing?

        //create the emptyenvelope connecting it to the SF object
        myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(**mySourceId**));

        //use the Recipient.fromSource method to create the Recipient
        dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(sender.name, // Recipient name
                                                                 sender.eAddress, // Recipient email
                                                                 null, //Optional phone number
                                                                 sender.role, //Role Name. Specify the exact role name from template
                                                                 new dfsle.Entity(**mySourceId**)); //source object for the Recipient
        //add email detail for the envelope
        myEnvelope = myEnvelope.withEmail(settingsDocusignTemplate.get(sourceName).email_subject__c, settingsDocusignTemplate.get(sourceName).email_body__c);

        //Could provide automatic notifications as well based off of criteria
        final boolean dfsle_reminder = settingsDocusignTemplate.get(sourceName).reminder__c;
        final integer dfsle_remindAfterDays = Integer.valueOf(settingsDocusignTemplate.get(sourceName).remindAfterDays__c); //wait before sending reminder
        
        //add Recipient to the Envelope
        myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });

        //create a new document for the Envelope
        dfsle.Document myDocument =     dfsle.Document.fromTemplate((dfsle.UUID)templateInfo.get('UUID'), // templateId in dfsle.UUID format
        (String)templateInfo.get('name')); // name of the template

        //add document to the Envelope
        myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument });

    try {
            
        System.debug('\tSending Envelope');
        dfsle.EnvelopeService.sendEnvelope(myEnvelope, // The envelope to send
                                                    true); // Send now?
    } catch (dfsle.DocuSignException docusignExcpt) {
        ErrorLogUtil.createErrorLogData(docusignExcpt,CLASS_NAME,METHOD_NAME,null,null);
    } catch (Exception excp) {
        ErrorLogUtil.createErrorLogData(excp,CLASS_NAME,METHOD_NAME,null,null);
    }
  • What is going wrong, is it not sending? Why are you using sourceID when creating the empty envelope? – bendowlingtech Nov 04 '20 at 10:00
  • The document is being sent but no merge is occurring with the Custom Fields that are on the Template. I would have thought that you would relate the SF object with the template to facilitate the merge, but this is not supported with the documentation. Rather the SF object is related to Envelope. The documentation from Docusign indicates that this is the way this is to be defined; https://developers.docusign.com/docs/salesforce/how-to/send-envelope – Richard Brescia Nov 05 '20 at 13:45

3 Answers3

0

Try adding this to your code just after "create a new document for the Envelope"

String opptyStr = (String) myOpportunity.Id + '~Opportunity';
        dfsle.CustomField myField = new dfsle.CustomField ('text', 'DSFSSourceObjectId', opptyStr, null, false, false);

//add document to the Envelope
myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument })
.withCustomFields(new List<dfsle.CustomField> {myField});

Technically merge fields are not supported but we can get around this issue by using custom fields with this code.

bendowlingtech
  • 474
  • 3
  • 11
0

withCustomFields(new List<dfsle.CustomField> {myField})

How do I add multiple fields to the list new List<dfsle.CustomField> {myField}?

Kavya
  • 1
0

So it ended up looking like this;

        templateInfo.put('Source_Reference',(String) mySourceId + '~Opportunity');

        dfsle.CustomField sourceField = new dfsle.CustomField ('text', 'DSFSSourceObjectId', (String)templateInfo.get('Source_Reference'), null, false, false);

        //add document to the Envelope
        myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument });

        //populate the custom fields on the Envelope
        myEnvelope = myEnvelope.withCustomFields(new List<dfsle.CustomField> {sourceField});