> You are reading the Docusign Developer Documentation. For clean Markdown of any page, append .md to the page URL.
>
> Documentation indexes by section:
> - APIs and SDKs: https://docusign.docs.buildwithfern.com/docs/llms.txt
> - Platform 101: https://docusign.docs.buildwithfern.com/platform/llms.txt
> - Extension Apps: https://docusign.docs.buildwithfern.com/extension-apps/llms.txt
> - Docusign CLI: https://docusign.docs.buildwithfern.com/docusign-cli/llms.txt
>
> Authentication (OAuth, JWT Grant, M2M): https://docusign.docs.buildwithfern.com/platform/auth
> Webhooks and Connect: https://docusign.docs.buildwithfern.com/platform/webhooks
>
> OpenAPI specifications: https://docusign.docs.buildwithfern.com/openapi.json
> MCP server: https://docusign.docs.buildwithfern.com/_mcp/server

# How to send an envelope with tabs

> Learn how to add tabs to your envelopes with the Apex Toolkit.

This topic demonstrates how to add [tabs](/docs/esign-rest-api/esign101/concepts/tabs) to your envelope.

## Prerequisites

1. Install the [Docusign eSignature for Salesforce](/docs/salesforce/how-to/apex-toolkit-install)  managed package.
2. Create a subdomain for your Salesforce organization by enabling "My Domain."
3. Select the **Docusign Setup** tab and complete the login step.

## Required data

Running the code in this how-to requires this data:

| Data element        | Description                                                                     |
| ------------------- | ------------------------------------------------------------------------------- |
| Content Document ID | The ID of a document stored in a Salesforce library.                            |
| Source ID           | The ID of the Salesforce Contact from whom the Docusign envelopes will be sent. |

## Step 1. Define your class and method

Create the class and method that will contain the code in this example. You can skip this step if you are adding this code to an existing class.

**`Apex`**

```java title="Apex"
public with sharing class SendEnvelopeWithTabsController {

@AuraEnabled

    public static void sendEnvelopeWithTabs() {
    }
}
```

## Step 2. Create your envelope definition

Use the [dfsle.EnvelopeService.getEmptyEnvelope](/docs/salesforce/apex-toolkit-reference/envelopeservice.html) method to create an empty envelope definition that will be subsequently completed, created, and sent. Specify the Salesforce source ID of the record in the [dfsle.Entity](/docs/salesforce/apex-toolkit-reference/entity.html) parameter that is to be used as the source object for the envelope.

**`Apex`**

```java title="Apex"
Id mySourceId = '00XXXXXXXXXXXXXXAM'; // The ID of the initiating Salesforce object

// Create an empty envelope
dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(
new dfsle.Entity(mySourceId));
// The initiating Salesforce entity
```

## Step 3. Specify a document for the envelope

Create a new [dfsle.Document](/docs/salesforce/apex-toolkit-reference/document.html) and add it to the envelope. This example uses the [dfsle.DocumentService.getDocuments](/docs/salesforce/apex-toolkit-reference/documentservice.html) method, passing in the `ContentDocumentId` of a document already stored in a Salesforce library. Then, it uses the Envelope's [dfsle.Envelope.withDocuments](/docs/salesforce/apex-toolkit-reference/envelope.html) method to add the document to the envelope.

**`Apex`**

```java title="Apex"
Id myDocumentId = '06XXXXXXXXXXXXXXAQ'; // The ID of a document stored in a Salesforce library
Id myFileId = [SELECT id from ContentVersion where ContentDocumentId = :myDocumentId LIMIT 1].id;

// Add document to the envelope
myEnvelope = myEnvelope.withDocuments(dfsle.DocumentService.getDocuments(ContentVersion.getSObjectType(), new Set<Id> { myFileId }));
```

## Step 4. Define the recipient tabs

Create one tab each of types Sign Here, Initial Here, Date Signed, and Text, and associate them with your document. These are just four of the many [tab types](/docs/esign-rest-api/reference/envelopes/enveloperecipienttabs#tab-types) supported by the Apex Toolkit. The Sign Here tab is placed in the document using [Auto-place (anchor tagging)](/docs/esign-rest-api/esign101/concepts/tabs/auto-place).

**`Apex`**

```java title="Apex"
dfsle.Tab myInitialHereTab = new dfsle.InitialHereTab()
    .withRequired(true) // Signing optional
    .withPosition(new dfsle.Tab.Position(
        1, // The document to use
        1, // Page number on the document
        320, // X position
        290, // Y position
        null, // Default width
        null)); // Default height

// Create a Text tab
dfsle.Tab myTextTab = new dfsle.TextTab()
    .withRequired(true) // Signer must enter value
    .withPosition(new dfsle.Tab.Position(
        1, // The document to use
        1, // Page number on the document
        210, // X position
        305, // Y position
        100, // 100 pixels wide
        null)); // Default height

// Create a Sign Here tab
dfsle.Tab mySignHereTab = new dfsle.SignHereTab()
    .withScale(1.5) // 1.5 scale
    .withRequired(true) // Signing mandatory
    .withAnchor(new dfsle.Tab.Anchor(
        'signed', // Anchor string
        false, // Do not allow white space in anchor string
        false, // Anchor string is not case sensitive
        'right', // Horizontal alignment in relation to the anchor text
        true, // Ignore if the anchor text is not present in the document
        true, // Must match the value of the anchor string in its entirety
        'pixels', // Unit of the x and y offset properties
        20, // X offset
        0)); // Y offset

// Create a Date Signed tab
dfsle.Tab myDateSignedTab = new dfsle.DateSignedTab()
    .withFormatting(new dfsle.Tab.Formatting(
        'Helvetica', // Font
        'default', // Font color
        14, // 14pt size,
        true, // Bold
        false, // Italic
        false, // Underline
        false, // Conceal value
        false)) // Fixed width
    .withPosition(new dfsle.Tab.Position(
        1, // The document to use
        1, // Page number on the document
        330, // X position
        470, // Y position
        null, // Default width
        null)); // Default height
```

## Step 5. Specify the recipient for the envelope

Create a [dfsle.Recipient](/docs/salesforce/apex-toolkit-reference/recipient.html) object for each recipient of the envelope and add tabs using the `withTabs` method. In this example, the envelope will have one signer recipient. Once a recipient is created, use the [withRecipients](/docs/salesforce/apex-toolkit-reference/envelope.html) method to add it to the envelope.

**`Apex`**

```java title="Apex"
dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(
    'Lily TheGSD', // Signer name
    'lilythegsd@gmail.com', // Signer email
    null, // Signer phone number
    'Signer 1', // Signer role
    null) // No Salesforce association
    .withTabs(new List<dfsle.Tab> { // Associate the tabs with this recipient
        myInitialHereTab,
        myTextTab,
        mySignHereTab,
        myDateSignedTab
    });

// Add recipient to the envelope
myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });
```

## Step 6. Send the envelope

Send the envelope using the [dfsle.EnvelopeService.sendEnvelope](/docs/salesforce/apex-toolkit-reference/envelopeservice.html) 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. The Apex Toolkit does not support sending a draft envelope. To send a draft envelope, you will need to call the [eSignature REST API](/docs/esign-rest-api) outside of the Apex Toolkit.

**`Apex`**

```java title="Apex"
myEnvelope = dfsle.EnvelopeService.sendEnvelope(
    myEnvelope, // The envelope to send
    true); // Send now?
```

## Step 7. Get the status

Docusign administrators can track the status of Docusign envelopes after sending them to recipients by using the Apex Toolkit [dfsle.StatusService.getStatus](/docs/salesforce/apex-toolkit-reference/statusservice.html) method. This method returns the current status of the envelope (Created, Deleted, Sent, Delivered, Signed, Completed, or Declined), the time and date of the most recent action on the envelope, and other information as a list of [dfsle.Envelope.Status](/docs/salesforce/apex-toolkit-reference/envelope.html) objects. This method is passed a set of Salesforce source records that are associated with envelopes and an integer specifying the maximum number of records that will be returned.

Getting envelope status is useful to ensure that the envelope operations you've already performed, such as sending, confirming delivery, signing, or completion, have been executed successfully and to detect new status changes for an envelope. You must be the sender of the envelopes to call the `dfsle.StatusService.getStatus` method.

**`Apex`**

```java title="Apex"
Id mySourceId; // The Salesforce ID of the object from which DocuSign envelopes were sent
// Retrieve the five most recent envelope statuses from the Salesforce source object
// The status results are sorted oldest to newest
List<dfsle.Envelope.Status> myStatus = dfsle.StatusService.getStatus(
    new Set<Id> { // IDs of the Salesforce objects with associated status
        mySourceId
    },
    5); // Maximum number of records to return
```

## Step 8. Execute your method

To execute your code, go to the [Developer Console](https://help.salesforce.com/s/articleView?language=en_US\&id=sf.code_dev_console.htm\&type=5) in Salesforce, open the **Debug** menu, then select **Open Execute Anonymous Window**. Type the accompanying code in the window and select **Execute**.

> **Note**
>
> View the source code for this how-to on GitHub: [Apex](https://github.com/docusign/code-examples-apex/blob/master/force-app/main/default/classes/SendEnvelopeWithTabsController.cls).

**`Apex`**

```java title="Apex"
RecipientTabsExample.sendEnvelopeMethod();
```

## Next steps

* See all available Apex Toolkit [How-to guides](/docs/salesforce/how-to).
* Learn more about [tabs](/docs/esign-rest-api/esign101/concepts/tabs) and how to use them in your documents.
* Learn [How to send an envelope](/docs/salesforce/how-to/send-envelope).
* See [How to perform unit testing](/docs/salesforce/how-to/unit-testing) to ensure that you have adequate code coverage.