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
chaitra prassinchaitra prassin 

How Docusign template is created with salesforce fields ?

-Hi everyone, 
Iam very new to Docusign. Can anyone help me?

- Now I tried to sent a Account Id in the code, it is sending correctly to the receipients,but Account name of that record is not merging in the template. So my question is 
1) I need to create the template in Docusign .right? not in salesforce .right?
-and from there, we get the template id, that we should give in the code for sending for signature .right?
-but i couldn't see any Account fields in the Docusign template to map it . I can see only Standard fields, which is the receipents 'field. so how this salesforce field should be added in the template ?

Requirement: when a status is changed in Account object, a trigger will call this Docusign Apex toolkit for sending the envelope to the receipients. This is working, but that Account name is not adding automatically in the document when sending to the recipient.
VinayVinay (Salesforce Developers) 
Hi Chaitra,

Can you try below steps.
  • Navigate to the object in salesforce org that you want to use with your DocuSign template.
  • Click on "DocuSign Templates" and select the template you created.
  • Map the Salesforce fields to the corresponding fields in your DocuSign template.
  • Save
Please mark as Best Answer if above information was helpful.

Thanks,
chaitra prassinchaitra prassin
Hi vinay, 
Thank you for the response.
I have done that in the template as below
template screenshot
And in code iam sending the account Id , but it is not merging the Account name.can you check the code ? and can you correct me if Iam wrong
 
public static EnvelopeSendResponse sendEnvelope(final Id mySourceId){//AccoundId=> mysourceID
        EnvelopeSendResponse response;
        try{
            //capture customer details
            Account mycustomer = [SELECT id,name,ownerId FROM Account WHERE Id=: mySourceId];
            //create a empty template
            dfsle.Envelope myenvelope = dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(mysourceId));
            
            //setup receipient data
            dfsle.Recipient myRecipient = dfsle.Recipient.fromSource('chaitra m.p', // Recipient name
                                                                     'chaitra@amdrodd.com', // Recipient email
                                                                     null, // Optional phone number
                                                                     'signerOne', // Role Name. Specify the exact role name from template
                                                                     new dfsle.Entity(mySourceId)); // Source object for the Recipient 
            // Add Recipient List to the Envelope
            myEnvelope = myEnvelope.withRecipients(new List < dfsle.Recipient > {myRecipient});
            //Build List of Documents to be inested into the Envelope:
        	// myTemplateId contains the DocuSign ID of the DocuSign Template
            dfsle.UUID myTemplateId = dfsle.UUID.parse('239f1718-19da-4322-89b2-838e68896819');
            
             
            
            //Add Salesforce Source Record to the mix, otherwise dynamic Custom Fields will not work:
           
            //create custom field
            String opptyStr = (String) mySourceId + '~Account';
       		dfsle.CustomField myField = new dfsle.CustomField ('text', 'DSFSSourceObjectId', opptyStr, null, false, false);
            
     		
            // Create a new document for the Envelope
            dfsle.Document myDocument = dfsle.Document.fromTemplate(myTemplateId, 'testTemplate'); 
            
            myEnvelope = myEnvelope.withDocuments(new list<dfsle.Document>{myDocument}).withCustomFields(new List <dfsle.CustomField>{myField});
    
            //Add documents to the Envelope:
            /*myEnvelope = myEnvelope.withDocuments(myDocument).withCustomFields(new List < dfsle.CustomField > {
                myCustomField1
            });*/
            //myEnvelope = myEnvelope.withDocuments(myDocument).withCustomFields(new List < dfsle.CustomField > {myCustomField1});

            //Finally send the Envelope:
            myEnvelope = dfsle.EnvelopeService.sendEnvelope(
                myEnvelope, // The envelope to send
                true); // Send now
                
     
        }catch(exception ex){
            
        }    
        return null;
    }