+ Start a Discussion
Asma SalesforceAsma Salesforce 

Hi All, I want to send email template using docusign. Please help me.

I have installed DocuSign manage package in salesforce and now I want to send DocuSign using apex but along with this, I want to send an email template. Please help me out

EmailTemplate emailTemplate = [Select Id,Subject,Description,HtmlValue,DeveloperName,Body from EmailTemplate where name ='test' limit 1];
 
Id mySourceId='0032y00000CRaIrAAL';
         
        //create empty template
         dfsle.Envelope myEnvelope=dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(mySourceId));
        system.debug('myEnvelope::: '+myEnvelope);
        Contact myContact=[Select id,Name,LastName,Email from Contact where id='0032y00000BmZsrAAF'];
        //create reciepient
        
        dfsle.Recipient myRecipient=dfsle.Recipient.fromSource(
            myContact.Name,//reciepient name
            myContact.Email,//recepient email
            null,//phone number
            'Singer 1',//Role Name Specify the exact role name from template
            new dfsle.Entity(myContact.Id));
         system.debug('myRecipient::: '+myRecipient);
        //add reciepient to the envelope
        
        myEnvelope=myEnvelope.withRecipients(new List<dfsle.Recipient>{myRecipient});
         system.debug('myEnvelope> '+myRecipient);
        dfsle.UUID myTemplateId=dfsle.UUID.parse('96dcc69d-e5ae-4ebd-a082-be87eb9cab79');
        
          system.debug('myTemplateId> '+myTemplateId);

        //create a new document for the envelope
        dfsle.Document myDocument=dfsle.Document.fromTemplate(
        myTemplateId,//templateId in dfsle.UUID format
        'test template'  //name of the template
        );
        
        
        //add document to the envelope
        system.debug('myDocument> '+myDocument);
        myEnvelope=myEnvelope.withDocuments(new List<dfsle.Document>{myDocument});
        system.debug('myEnvelope===> '+myEnvelope);
        //send the envelope
        myEnvelope=dfsle.EnvelopeService.sendEnvelope(
        myEnvelope,//the envelope to send 
            true//send now ?=true
        );
Please help me.