Guides
These docs are for v4.6. Click to read the latest docs for v4.29.

Example 2: Send signature request from Account

This example shows sending a signature request from an Account with two signers and two documents from Notes & Attachments who will sign sequentially, each signer signing one of the docs and using form fields instead of text tags.

// Get the Account, two attachments, and our two signers
Account acct = [SELECT Id FROM Account WHERE Name = 'Test Account' LIMIT 1];

Attachment doc1 = [SELECT Id FROM Attachment
                   WHERE ParentId = :acct.Id AND Name = 'doc1.docx'];

Attachment doc2 = [SELECT Id FROM Attachment
                   WHERE ParentId = :acct.Id AND Name = 'doc2.docx'];

Contact signer1 = [SELECT Id, Name, Email FROM Contact
                   WHERE AccountId = :acct.Id AND Name = 'Signer 1'];

Contact signer2 = [SELECT Id, Name, Email FROM Contact
                   WHERE AccountId = :acct.Id AND Name = 'Signer 2'];

//Set up the HelloSign.HelloSignDocumentService.SignatureRequest object
HelloSign.HelloSignDocumentService.SignatureRequest sigReq =
   new HelloSign.HelloSignDocumentService.SignatureRequest();

sigReq.title = 'Example Form Field Docs';
sigReq.subject = 'Please Sign on the Second Page';
sigReq.message = 'Hello signee, please sign the doc. Thank you.';
sigReq.useTextTags = false;

// Set up your signers from the Contact records
sigReq.signers.add(new HelloSign.HelloSignDocumentService.Signer());
sigReq.signers[0].name = signer1.Name;
sigReq.signers[0].email = signer1.Email;


sigReq.signers.add(new HelloSign.HelloSignDocumentService.Signer());
sigReq.signers[1].name = signer2.Name;
sigReq.signers[1].email = signer2.Email;

// Set up documents
List<HelloSign.HelloSignDocumentService.Document> documents =
   new List<HelloSign.HelloSignDocumentService.Document>();

documents.add(new HelloSign.HelloSignDocumentService.Document());
documents[0].recordId = doc1.Id;

documents.add(new HelloSign.HelloSignDocumentService.Document());
documents[1].recordId = doc2.Id;

// Set up two signature form fields for the second document
documents[1].formfields.add(new HelloSign.HelloSignDocumentService.FormField());
HelloSign.HelloSignDocumentService.FormField firstSignature = documents[1].formfields[0];

firstSignature.type = HelloSign.HelloSignDocumentService.FormFieldType.SIGNATURE;
firstSignature.signer = sigReq.signers[0];
firstSignature.name = 'Signature1';
firstSignature.required = true;

documents[1].formfields.add(new HelloSign.HelloSignDocumentService.FormField());
HelloSign.HelloSignDocumentService.FormField secondSignature = documents[1].formfields[1];

secondSignature.type = HelloSign.HelloSignDocumentService.FormFieldType.SIGNATURE;
secondSignature.signer = sigReq.signers[1];
secondSignature.name = 'Signature2';
secondSignature.x = 200;
secondSignature.y = 200;
secondSignature.height = 50;
secondSignature.width = 50;
secondSignature.required = true;

// Send the signature request
HelloSign.HelloSignDocumentService.SendSignatureResponse response =
    HelloSign.HelloSignDocumentService.sendSignature(acct.Id, documents, sigReq);