function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nama bekannama bekan 

In the new DocuSign Apex Toolkit, How to send data from Merge Fields.

Do you know how to use the new Apex Toolkit Docusign API to transfer data to a custom field (a Salesforce merge field)?

This is the instruction I've been following: https://developers.docusign.com/docs/salesforce/how-to/send-envelope/

However, there are no examples of custom fields being filled with Salesforce data. I attempted to use a custom field class, however it only has read-only properties.

What is the best way to send salesforce data to a template document?


Nama
 
Best Answer chosen by nama bekan
Tarun DasTarun Das
public class SampleMergeFields {

 public static void sendMergeFieldTemplate() { 

     //create recipient
     dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(
                                     'XXXXX', //name of recipient
                                     'xxxx.xx@xxx.com', //email of the recipient
                                     null,
                                     'Signer 1', //match role value defined in the template
                                     new dfsle.Entity(UserInfo.getUserId())); //pass in the ID of the source object here

    //create document                                 
    dfsle.UUID myTemplateId = dfsle.UUID.parse('XXXXX-XXXX-XX'); //Docusign template Id
    dfsle.Document myDocument =dfsle.Document.fromTemplate(
                                        myTemplateId, // templateId in dfsle.UUID format
                                        'myTemplate');

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

   dfsle.Envelope myEnvelope = new dfsle.Envelope(
                               null,
                               null,
                               null,
                               null,
                               new List<dfsle.Document> { myDocument },
                               null,
                               new List<dfsle.CustomField> { myCustomField1 },
                               null,
                               'Hello from DocuSign',
                               'My Message',
                               null,
                               null);
   myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });
   // Send the envelope
   myEnvelope = dfsle.EnvelopeService.sendEnvelope(
                                        myEnvelope, // The envelope to send
                                        true); // Send now?

 } 

}


Using the Apex toolkit and the aforementioned code, you may establish merge fields data for the Salesforce merge fields defined in your DocuSign template.

Note that in the Custom field entitled '##SFStudent c,' you must specify the RecordID of the Salesforce.com record from which the template should pull values. For example, suppose you have a custom object Student c in your org with two fields a1 c and a2 c, and both of these attributes are present on a template you're delivering. In this scenario, the custom field's name should be '##SF'+API. Salesforce.com Id of the record should be the name of the object and the value of the custom field.

Merge fields from several Salesforce.com objects can also be defined. You'll have to establish additional custom fields for the objects in that situation. Assume you have a template that includes fields from both Account and Contact. In that instance, you'll need to create two custom fields called '##SFAccount' and '##SFContact,' and populate them with the appropriate values.

Please keep in mind that in order for this to work, Salesforce connect must be defined in the DocuSign account you're using, and it must point to the Salesforce.com org where the toolkit is installed.

Could you please test this on your end?