Created
March 8, 2017 09:05
-
-
Save codingdawg/36be275685d0d09e3a0140e2a4d929e6 to your computer and use it in GitHub Desktop.
Docusign Soap CreateEnvelopeFromTemplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Step #1) Buiding Template, Recipient and Envelope information | |
// 1.1) Put the created template from DocuSign | |
DocuSignAPI.TemplateReference templetRef = new DocuSignAPI.TemplateReference(); | |
templetRef.Template = aa3d9632-1595-4fef-87dd-1795334edf9d; | |
templetRef.TemplateLocation = 'Server'; | |
DocuSignAPI.ArrayOfTemplateReference templetRefs = new DocuSignAPI.ArrayOfTemplateReference(); | |
templetRefs.TemplateReference = new DocuSignAPI.TemplateReference[]{templetRef}; | |
system.debug('templetRefs: '+templetRefs); | |
// 1.2) Create a Recipient | |
DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient(); | |
recipient.Email = docuSign_email; | |
recipient.UserName = docuSign_fName+' '+docuSign_lName; | |
recipient.Type_x = 'Signer'; | |
recipient.ID = 1; | |
recipient.RoutingOrder = 1; | |
recipient.RequireIDLookup = false; | |
recipient.RoleName = 'Signer 1'; | |
DocuSignAPI.ArrayOfRecipient1 recipients = new DocuSignAPI.ArrayOfRecipient1(); | |
recipients.Recipient = new DocuSignAPI.Recipient[]{recipient}; | |
ArrayOfTemplateReferenceRoleAssignment tras = new ArrayOfTemplateReferenceRoleAssignment(); | |
TemplateReferenceRoleAssignment assign = new TemplateReferenceRoleAssignment(); | |
assign.setRoleName(recipient.getRoleName()); | |
assign.setRecipientID(recipient.getID()); | |
tras.getRoleAssignment().add(assign); | |
templetRef.setRoleAssignments(tras); | |
system.debug('recipients: '+recipients); | |
// 1.3) Construct the envelope information | |
DocuSignAPI.EnvelopeInformation envelopeInfo = new DocuSignAPI.EnvelopeInformation(); | |
envelopeInfo.Subject = 'Terms of Agreement for your Signature'; | |
envelopeInfo.EmailBlurb = 'We are sending you this request for your electronic signature, please review and electronically sign by following the link above. '; | |
envelopeInfo.AccountId = accountId; | |
//Populate Application as a Custom Field in Envelope | |
DocuSignAPI.CustomField custFiled = new DocuSignAPI.CustomField(); | |
custFiled.Name = 'DSFSSourceObjectId'; | |
custFiled.Value = docuSign_appID; | |
custFiled.show = 'False'; | |
custFiled.Required = 'True'; | |
custFiled.CustomFieldType = 'Text'; | |
DocuSignAPI.ArrayOfCustomField CustFields = new DocuSignAPI.ArrayOfCustomField(); | |
//CustFields.CustomField = new DocuSignAPI.CustomField[]{custFiled,accFiled}; | |
CustFields.CustomField = new DocuSignAPI.CustomField[]{custFiled}; | |
envelopeInfo.CustomFields = CustFields; | |
system.debug('envelopeInfo: '+envelopeInfo); | |
// Step #2) Create a Envelope with informtion created from step #1 and SendEnvelope | |
System.debug('Calling the API'); | |
//DocuSignAPI.EnvelopeStatus es = dsApiSend.CreateAndSendEnvelope(envelope); | |
DocuSignAPI.EnvelopeStatus envelopStatus = dsApiSend.CreateEnvelopeFromTemplates(templetRefs, recipients,envelopeInfo,true); | |
envelopeId = envelopStatus.EnvelopeID; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment