How to transform PDF form fields
This topic demonstrates how to use PDF form field transformation within the Apex Toolkit to convert PDF form fields in your Salesforce library documents to Docusign tabs automatically.
Prerequisites
- Install the Docusign eSignature for Salesforce managed package.
- Create a subdomain for your Salesforce organization by enabling “My Domain.”
- Select the Docusign Setup tab and complete the login step.
- Upload a PDF containing form fields to a Salesforce library by going to App Launcher > Sales Console > Files and selecting Upload Files.
Required data
Running the code in this how-to requires this data:
Step 1. Define your public class and method
Create one public class and one public method that will contain the code for this how-to. You can skip this step if you are adding this code to an existing class.
Step 2. Create an empty envelope and recipient
Use the dfsle.EnvelopeService.getEmptyEnvelope method to create a new envelope. Specify the Salesforce Contact ID of the record in the Entity parameter that is to be used as the sender of the envelope. Create a Recipient object for each recipient of the envelope. These recipient objects contain the full set of data on the recipient’s role in the signing process: their role, authentication data, status in the workflow, and contact settings. In this how-to, the envelope will have one recipient: a document signer. Once a recipient is created, use the withRecipients method to add it to the envelope.
The accompanying code demonstrates the workflow for adding recipient data to the envelope.
Step 3. Get a document with PDF options enabled
Create a new dfsle.Document using the dfsle.DocumentService.getDocuments method. In this how-to, you will use a PDF file containing form fields that you’ve uploaded to a Salesforce library. To get the Content Version ID of that document, write a query using Salesforce Object Query Language (SOQL) to find Content Versions associated with the Content Document ID. Passing that Content Version ID to the getDocuments method will return a list of dfsle.Document objects. Index the returned list to get the first document and use the .withPdfOptions method to enable PDF form field transformation. Then add the document to your envelope.
The accompanying code demonstrates how to get your document from Salesforce and add it to the envelope.
Step 4. Send the envelope
Send the envelope using the dfsle.EnvelopeService.sendEnvelope method. The sendNow parameter is set to true to indicate that you want to send the envelope immediately. Setting the sendNow parameter to false will save the envelope as a draft so it can be sent later.
The accompanying code demonstrates how to send the envelope.
Step 5. Execute your method
To execute your code, go to the Developer Console in Salesforce, open the Debug menu, then select Open Execute Anonymous Window. Type the accompanying code in the window and select Execute.
If you skipped step 1 and added your code to an existing class or method, you’ll need to replace the class and method names with your own.
View the source code for this how-to on GitHub: Apex
Expected response
If your API call is successful, the recipient should receive an email notification asking them to sign the documents in the envelope. All form fields from your PDF will be transformed to Docusign tabs.
Next steps
- See all available Apex Toolkit How-to guides.
- Learn more about PDF form field transformation.
- See How to perform unit testing to ensure that you have adequate code coverage.