Is it possible to generate a PDF using Apex and then embed the 'Signature tab' of DocuSign into the PDF?
For example: in the Contract Object we have a text area in which the user could add legal agreements, such as:
Agreements (Text Area):
I agree that this and that are true and correct…
Signature: signature_tag
We would like that when a user clicks on a custom button, called 'Send to Docusign', an Apex code is run that will convert the agreements text area above into a PDF, then it converts the tag into a 'Signature tab' that DocuSign interprets as the location where the client needs to sign.
Is this possible?
Thanks.
Best Answer
It looks like it is possible, although the steps are a little different than what you described.
From the DocuSign documentation, you can send the HTML body to their REST endpoint, and specify in the document body where you want the DocuSign tags to be.
Creating a Signable HTML Document
To pass in HTML to create a new HTML document in an envelope, use the following steps:
In the JSON request body for a standard REST POST
/accounts/{accountId}/envelopes
method call, ensure that you have at least one document defined in the request’s documents block.For each HTML document in this section, add an
htmlDefinition
node.Within the
htmlDefinition
node, insert another node called source. Add your page’s HTML to the value of source. The following example shows an example documents node of a request to create a new signable HTML document.There are two ways to specify the fields you want on the document:
The signature tab type, for example, is
<ds-signature/>
. So if you can add that to the document that is passed to DocuSign's endpoint, then you'll be just fine. DocuSign will create the document for you, and then you can retrieve it on another call from Salesforce.So to summarize: your button would call an Apex code that calls a Visualforce page renderer, that will then get the body and pass to this endpoint. When the document is created by DocuSign you will need to make another call to retrieve the created document and, if necessary, save it as an attachment to the record on Salesforce.