---
schema_version: "1"
id: 36d9dd145f96a28f0477b54d7d5ec6c1cb123f9f53b0d0739a3a1caad76b3dbb
title: Create a Form Based on an Apex Class
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/service/264-0-0/messaging_whatsapp_create_form_apex_class.md
canonical_url: https://help.salesforce.com/s/articleView?id=service.messaging_whatsapp_create_form_apex_class.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: a62aa115d5c7cfa9b4dc6933069afe34bc3be9a9f73d900e685fcde12f3f1b50
description: Apex-based forms offer more flexibility than global action-based forms, enabling you to create both static and dynamic WhatsApp messages. To create an Apex-based form, create the Apex class, and then link it to a form messaging component. When the messaging end user submits their responses to the form, Salesforce executes the Apex, sending the data to Salesforce. You must configure how to save that data.
products:
  - Service Cloud
  - Digital Engagement
release: "264"
---
# Create a Form Based on an Apex Class

Apex-based forms offer more flexibility than global action-based forms, enabling you to create both static and dynamic WhatsApp messages. To create an Apex-based form, create the Apex class, and then link it to a form messaging component. When the messaging end user submits their responses to the form, Salesforce executes the Apex, sending the data to Salesforce. You must configure how to save that data.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <tbody>
          <tr class="">
            <td class="slds-cell-wrap" colspan="2" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=service.messaging_editions.htm&amp;type=5&amp;language=en_US" target="_blank">View supported editions.</a></td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <span style="vertical-align:text-bottom;display:inline-block;"><img style="margin-bottom:0;" src="https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/resources-global/_corporate/images/checkmark.png" alt="Checkmark"></span>
              <strong>This article applies to:</strong>
            </td>

            <td class="slds-cell-wrap" style="vertical-align:top;">Enhanced WhatsApp channels</td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <span style="vertical-align:text-bottom;display:inline-block;"><img style="margin-bottom:0;" src="https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/resources-global/_corporate/images/crossmark.png" alt="X icon"></span>
              <strong>This article doesn’t apply to:</strong>
            </td>

            <td class="slds-cell-wrap" style="vertical-align:top;">Enhanced In-App Chat, Enhanced Web Chat v1, Enhanced Web Chat v2, Enhanced
              Facebook Messenger, Standard and Enhanced SMS, Enhanced Apple Messages for Business,
              Enhanced LINE, and Bring Your Own Channel</td>

          </tr>
        </tbody>
      </table> <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d153988e97">User Permissions
              Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d153988e97 ">To create messaging components: </td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d153988e97 ">
              <p>Customize Application AND View Setup and Configuration</p>
              <p>OR</p>
              <p style="margin-bottom:0;">System Administrator</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d153988e97 ">To send and receive messages in Messaging: </td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d153988e97 ">Messaging Agent</td>

          </tr>
        </tbody>
      </table>

#### See Also

- [_Salesforce Help:_ WhatsApp Flows](https://help.salesforce.com/s/articleView?id=service.messaging_whatsapp_flows.htm&language=en_US)
- [_Salesforce Help:_ Dynamic WhatsApp Flows](https://help.salesforce.com/s/articleView?id=service.messaging_whatsapp_dynamic_flows.htm&release=264.0.0&type=5 "Move beyond static forms. WhatsApp dynamic Flows enable you to build data-driven, highly personalized conversational experiences that adapt to users and input data in real time. Leverage these sophisticated capabilities to build guided forms or multi-step wizards to accomplish tasks, such as dynamic quoting, appointment scheduling and checkins, personalized onboarding, and guided selling.")
- [_Salesforce Help:_ Create and Send Secure Forms in Messaging Sessions](https://help.salesforce.com/s/articleView?id=service.messaging_components_forms.htm&language=en_US)

## Create the Apex Class

1. From Setup, in the Quick Find box, enter Apex Classes, then select **Apex Classes** and click **New**.
2. In the class editor, enter this class definition.
3. Click **Save**.

## Create the Form Messaging Component

1. Go to the Messaging Components page in Setup.
2. Click **New Component**.
3. Select the Form messaging component and click **Next**.
4. Select **Apex Class** and click **Next**.
5. Enter the form title, select the Apex class that you just created, and then click **Next**. The title appears in the messaging session as a link to the form.
    
    ![Messaging Component setup flow with Form Title and Apex Class fields filled out.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/support_channels/images/messaging/messaging_component_form_from_apex_class.png)
6. Enter a name and description of your component. Messaging end users can’t see this information. But, it helps service reps quickly identify the component’s purpose when choosing a message to send from the Service Console.
7. Click **Done**. The Messaging Component Builder opens.

## Add the Flow Format to the Apex Form Messaging Component

To create a WhatsApp Flow, add a Flow format to the form messaging component. Configure the message content in the flow.

1. Open the Apex-based form messaging component. To create an Apex-based form messaging component, see [Create and Send Secure Forms in Messaging Sessions](https://help.salesforce.com/s/articleView?id=service.messaging_components_forms.htm&language=en_US).
2. In the Component Formats section, click **Details**, and then click **Add Format**.
3. Select **Flow**, and then click **Done**. The format controls how the component looks in messaging sessions. Each messaging component is available in one or more formats, and some formats work only in certain channels. For a list of formats that each channel supports, see [Messaging Component Types and Formats](https://help.salesforce.com/s/articleView?id=service.messaging_component_formats.htm&language=en_US). It’s a good idea to add at least one supported format for each channel where the component will be sent. If no formats are added, the component uses the default text format.
4. In the left-hand sidebar, under Component Formats, click **Flow**.
    
    ![The Flow layout selected in the Messaging Component Builder.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/support_channels/images/messaging/messaging_apex_form_flow_format_properties.png)
5. In the Initial Message section, enter the message that appears when a conversation starts with the customer.
6. In the Launch Button section, enter a name for the button that launches this WhatsApp Flow.
    
    ![Messaging Component Builder canvas showing a preview of the Initial Message and Launch Button text.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/support_channels/images/messaging/messaging_form_component_whatsapp_flow_launch_button.png)
7. To add a screen, click **Add Screen**. You can add multiple screens to the Flow.
8. Enter a title for the screen.
9. To add content to the screen, click **Add Content**.
10. Expand one or more content type boxes and then select one or more screen elements. For example, expand the Media and Selection boxes and then select **Image** and **Multi-Select Question**. To show content and control screen navigation using conditional logic, under the Conditional Logic box, select a Switch or If screen element.
    
    ![The Add Content screen from the Messaging Component Builder.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/support_channels/images/messaging/messaging_flow_format_add_content.png)
11. To add the selected screen elements to the screen, click **Done**. Each screen can have only one footer with a button. Each button either navigates to a subsequent screen in the flow or completes the flow. A button can’t navigate to a former screen. For example, screen 2 can’t navigate back to screen 1.
12. In the Component Properties, configure each screen element.
    
    ![Screen element configuration options in the Component Properties panel.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/support_channels/images/messaging/messaging_form_component_whatsapp_flow_screen1_details.png)
13. The canvas shows a preview of the screen that is currently expanded.
    
    ![Messaging Component Builder canvas showing how the Flow Screen Title Text and the Dropdown Selection Text populate.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/support_channels/images/messaging/messaging_form_component_whatsapp_flow_screen1_details2.png)
14. To create a second screen, click **Add Screen** again.
15. Enter the details for the second screen.
16. If this screen is the last screen in the Flow, add a Footer with a Complete footer action, which completes the Flow.
17. Expand the Screen 1 section, select the Footer content type, and configure the footer action to navigate to the next screen.
    
    ![Messaging Component Builder canvas showing how the Footer Action and Next Screen settings appear.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/support_channels/images/messaging/messaging_form_component_whatsapp_flow_screen1_with_footer.png)
18. After you update the Flow format properties, save the messaging component.
19. In the left-hand sidebar, under Component Formats, click the Text format type to update its properties. The plain text version is sent if your preferred format isn’t available or doesn’t load. While global action-based and Apex class-based forms can’t be sent in plain text, you can edit your component’s plain text version so it contains a link to a public form or shows a text-only list of the questions that appear in your form.
    
    ![Messaging Component Builder with the Text component format layout shown.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/support_channels/images/messaging/messaging_components_form_format_text.png)
20. When you’re done editing your component, click **Save**. Your component is saved in a draft state.
21. To make this messaging component available to service reps, click **Activate**.
22. To take the component offline—for example, to give you time to reconfigure it—open it in the Messaging Component Builder and click **Deactivate**. When you're ready, activate it again.

## Configure an Expiration Timer for the Component

By default, an Apex-based form expires 5 minutes after being sent to the customer. Optimally, customize the expiration timer in the component builder.

1. Open the Apex-based form messaging component in the component builder.
2. Select **Customize**.
3. Fill in the Apex Class and Time to Expiration (Minutes) fields.
4. Save your changes and activate the component.