DocuSign Apps Launcher: Merge Fields not populating in DocuSign Envelopes and not writing back to Salesforce.

DocuSign never officially supported merge fields in DocuSign Apps Launcher (DAL) and Apex Toolkit. Merge Fields worked without configuration changes up to version 2.4.x since DocuSign was passing in the same DSFSSourceObjectId custom field that DocuSign for Salesforce (DFS) was using. To support the new model of merge fields moving forward and not to confuse Connect in situations where both DFS and DAL are installed, DocuSign changed the custom fields in DAL version 2.5+. 

Using the Apex Toolkit it is possible to add this custom field in your code and have merge fields continue to work. DocuSign will update this article if merge field support is added to DAL.

Prerequisite: your account must have the feature Envelope Custom Fields turned on. 

In the below example the Opportunity source ObjectId is added to the envelope:

String opptyStr = (String) myOpportunity.Id + '~' + myOpportunity.Id.getSobjectType();
dfsle.CustomField myField = new dfsle.CustomField ('text', 'DSFSSourceObjectId', opptyStr, null, false, false);
myEnvelope = myEnvelope.withCustomFields(new List<dfsle.CustomField> {myField});

You would implement this with your Object.Id.

String opptyStr = (String)yourObject.Id + '~' + yourObject.Id.getSobjectType();

Below is a full working code block you can test in the Execute Anonymous Window in Salesforce. Just change Account, Opportunity, and Contact to match your Salesforce world to test.

//Get the Salesforce Opportunity Id
Opportunity myOpportunity = [SELECT Id FROM Opportunity WHERE Name = 'Sailcloth' LIMIT 1];

// Create an empty envelope with Opportunity Id as the source Id
dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(myOpportunity.Id));

//Find your contact to add
Contact myContact = [SELECT Id, Name, Email FROM Contact WHERE Name = 'Black Beard' LIMIT 1];

//use the Recipient.fromSource method to create the Recipient
dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(
                    myContact.Name, // Recipient name
                    myContact.Email, // Recipient email
                    null, //Optional phone number
                    'Customer', //Role Name. Specify the exact role name from template
                    new dfsle.Entity(myContact.Id)); //source object = Opportunity

//add Recipient to the Envelope
myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });

//myTemplateId contains the DocuSign Id of the DocuSign Template
dfsle.UUID myTemplateId = dfsle.UUID.parse('874821b3-9018-48d1-b590-xxxxxxxxxx');

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

String opptyStr = (String) myOpportunity.Id + '~' +  myOpportunity.Id.getSobjectType();

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});
// Send the envelope.
myEnvelope = dfsle.EnvelopeService.sendEnvelope(
            myEnvelope, // The envelope to send
            true); // Send now.

Connect Objects: 
Traditional DocuSign for Salesforce based Connect objects that rely on Envelope External Source ID will also be impacted. The Envelope External Source ID is the UI name for the DSFSSourceObjectID. 

Thus, if you have Update fields in Connect Objects that rely on the above in the Select Where clause, then you would either want to find another way to match a record to an envelope or institute the workaround outlined above using the Apex Toolkit.