---
schema_version: "1"
id: 0a835c7d0ac84779135a74f9e6765806fe9f6b622763ea1f935f83f583966bb6
title: Use a Screen Flow to Pass Input Data to a Dynamic WhatsApp Flow
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/service/264-0-0/messaging_dynamic_whatsapp_flow_input_data.md
canonical_url: https://help.salesforce.com/s/articleView?id=service.messaging_dynamic_whatsapp_flow_input_data.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 2a3e0cb02b9bb82a0d292cdd3d44569b8e386a12958bcf45864e082575d5f766
description: The screen flow can collect customer data and securely pass it into variables. These variables can then serve as input for the dynamic WhatsApp Flow that is created with an Apex-based form messaging component. To add personalized content to the message, in the Apex-based form messaging component, add dynamic references to this input data. For example, to schedule a veterinary appointment, the screen flow collects specific details, such as the type of animal and the issue, and dynamically passes this information to the Apex-based form messaging component.
products:
  - Service Cloud
  - Digital Engagement
release: "264"
---
# Use a Screen Flow to Pass Input Data to a Dynamic WhatsApp Flow

The screen flow can collect customer data and securely pass it into variables. These variables can then serve as input for the dynamic WhatsApp Flow that is created with an Apex-based form messaging component. To add personalized content to the message, in the Apex-based form messaging component, add dynamic references to this input data. For example, to schedule a veterinary appointment, the screen flow collects specific details, such as the type of animal and the issue, and dynamically passes this information to the Apex-based form messaging component.

### 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;language=en_US" target="_blank">View supported editions.</a></td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <a name="messaging_dynamic_whatsapp_flow_input_data__image_cgj_vgf_5cc"><!-- --></a><span style="vertical-align:text-bottom;display:inline-block;"><img style="margin-bottom:0;" id="messaging_dynamic_whatsapp_flow_input_data__image_cgj_vgf_5cc" 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, Unified WhatsApp</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, Standard and 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="d165230e95">User Permissions
              Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d165230e95 ">To create messaging components: </td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d165230e95 ">
              <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="d165230e95 ">To send and receive messages in Messaging: </td>

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

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

When you create an Apex-based form messaging component, these standard input parameters are available, by default.

 
| Parameter | Description |
| --- | --- |
| `FormData` | Stores input data passed to the flow. The data is stored as a JSON string of key-value pairs. To reference this data, you must define the structure of the data in a data model. The structure of the data model must match the structure of the JSON. You can access this data using Apex or a screen flow. |
| `FormEntryScreenId` | Stores the ID of the entry screen, which is the first screen that the messaging end user sees. |

You can find these default parameters on the Parameters tab of the Component Details section.![Shows the FormData and FormEntryScreenID parameters that are created, by default.](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_apex_parameters.png)

To help you understand how to use these parameters and a screen flow to pass in input data, let’s look at an example.

1. Open the Flow format of the Apex-based form messaging component.
    1. In the Flow format, click **Manage Data** to define a data model for all input data being passed in from the FormData parameter.
        
        For example, the FormData parameter stores this input data.
        
        `{“FirstName”:“Albert”,“LastName”:“Costa”,“isStudent”:“true”}`
    2. To add a field to the data model, click **Add Field** and configure its properties.
        
        Perform this step for every field in the FormData parameter. To create a structure, select the Object data type for a field, and add nested fields.
        
        ![The data model has three defined fields.](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_format_flow_data_model.png)
    3. After you’re done defining the data model, save it.
2. To use the value from a data model field in a Flow property, add a dynamic reference.
    1. Open the Flow format and locate the property for which you want to use a dynamic reference.
        
        For example, you can add a dynamic reference for the Text Content field for a Body screen element.
    2. In the Type field, select **Dynamic Reference**.
    3. In the Select the Reference Field, select the data model field.
        
        ![The FirstName input field, LastName input field, and the selected animal type on Screen 1 can all be used as the dynamic reference.](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_format_flow_dynamic_reference.png)
        
        Dynamic references can pull data from data model fields or input fields defined in a screen.
    4. In the canvas, preview the dynamic reference.
        
        ![The dynamic reference pulls data from the FirstName input field.](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_format_flow_dynamic_reference_result.png)
3. To pass data into the messaging component, create a screen flow.
    
    The screen flow can collect data from the messaging session and use it in the Apex-based Form messaging component. To illustrate how this works, let’s create a sample screen flow.
    
    1. Define the screen flow variables.
        
         
        | Variable | Value |
        | --- | --- |
        | `sessionId` | Stores the messaging session record ID. |
        | `initialData` | Stores the input data for the Apex-based form. The fields in this JSON string must match the field names that you added to the data model. |
        | `initialScreenId` | Stores the initial screen ID for the Apex-based form. This is the first screen that a messaging end user sees. |
        | `meuName` | Stores the name of the messaging end user. |
        | `items` | This collection variable stores a list of items. |
    2. In the screen flow, add these actions in this order. To retrieve data from a Salesforce object, add a Get Records action. To assign values to the screen variables, add an Assignment action.
        
         
        | Action | Description |
        | --- | --- |
        | getSession Get Records action | Get the messaging session based on the session ID. You can get relevant data from that messaging session. In this case, it retrieves and stores the Id and MessagingEndUserId field values. |
        | getMEU Get Records action | Get the Messaging User record based on the MessagingEndUserId. |
        | setMEUName Assignment action | Set the `meuName` variable to the value of the Messaging User Name field from the Messaging User record. |
        | getDynamicFlowItem Get Records action | Get all DynamicFlowItem records from the DynamicFlowItem object, storing the ID, ItemId\_\_c, and itemTitle\_\_c fields in the `items` collection variable. |
        | GenerateJson Apex action | Converts the input data from the `items` and `meuName` variables to the JSON format. The fields of the JSON object are mapped to the fields in the flow’s data model. This action is based on an Apex class. See sample Apex class after this table. |
        | setData Assignment action | Set the `InitialData` variable to the value of the generated JSON action. |
        
        This Apex class transforms structured input data—a user's name and a list of Salesforce records—into a single JSON string. This JSON string is then used to pass input data to the Apex-based form messaging component.
        
        ```
        public class FlowJSONBuilder {
        
            // 1. Input parameters
            public class FlowInput {
                @InvocableVariable(label='User Name' required=true)
                public String meuName;
        
                // CHANGE: Use List<SObject> instead of List<DynamicFlowItems__c> to avoid compile error
                @InvocableVariable(label='Flow Items' required=true)
                public List<SObject> items; 
            }
        
            // 2. Output parameters
            public class FlowOutput {
                @InvocableVariable(label='Generated JSON')
                public String jsonString;
            }
        
            // 3. Internal Wrapper classes
            public class JSONStructure {
                public String greeting;
                public List<ItemWrapper> items;
            }
        
            public class ItemWrapper {
                public String id;
                public String title;
            }
        
            // 4. Main Method
            @InvocableMethod(label='Generate Custom JSON' description='Builds the JSON string from Flow items')
            public static List<FlowOutput> generateJson(List<FlowInput> requests) {
                List<FlowOutput> outputs = new List<FlowOutput>();
        
                for (FlowInput request : requests) {
                    FlowOutput output = new FlowOutput();
                    
                    JSONStructure jsonRoot = new JSONStructure();
                    jsonRoot.greeting = 'Hello ' + request.meuName + '!';
                    jsonRoot.items = new List<ItemWrapper>();
        
                    if (request.items != null) {
                        // Loop through generic SObjects
                        for (SObject genericRec : request.items) {
                            // CAST the generic SObject to your specific Custom Object
                            DynamicFlowItem__c rec = (DynamicFlowItem__c)genericRec;
                            
                            ItemWrapper item = new ItemWrapper();
                            item.id = rec.itemId__c;     
                            item.title = rec.itemTitle__c; 
                            jsonRoot.items.add(item);
                        }
                    }
        
                    output.jsonString = JSON.serialize(jsonRoot);
                    outputs.add(output);
                }
        
                return outputs;
            }
        }
        ```
    3. Add a Screen action to the screen flow, and then drag the Enhanced Message component onto the screen.
        
        ![The Enhanced Messaging component calls the dynamic WhatsApp flow and provides input data.](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_screen_flow_msg_component.png)
    4. To specify the input data, set these Enhanced Message component properties as shown.
        
         
        | Property | Value |
        | --- | --- |
        | Messaging Session ID | Select `sessionId`, the screen flow variable that contains the session ID. |
        | Messaging Component Name | Select the name of the Apex-based form messaging component that you created. |
        | Apex Form Data | Select `initialData`, the screen flow variable that contains the input data. |
        | Apex Form Entry Screen ID | Select `initialScreenId`, the screen flow variable that contains the initial screen ID. |
        
        At run time, the screen action invokes the Apex-based form messaging component and passes this input data to it.
    5. Save and activate the screen flow.
        
        ![The Enhanced Messaging component calls the dynamic WhatsApp flow and provides input data.](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_whatsapp_screen_flow.png)
4. To enable a service rep to run the screen flow, [embed the active screen flow in the service console page](https://help.salesforce.com/s/articleView?id=platform.flow_distribute_internal_lab.htm&language=en_US&type=5).
    
    For example, add the Flow component to the Messaging Session record page.
    
    ![The Messaging Session record page has a component for the flow.](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_embedded_screen_flow_in_service_console.png)
    
    During a messaging session, to launch the screen flow from the page, the service rep can click **Next**.
    
    To insert the flow’s messaging component into the conversation with the customer, the service rep can click **Insert Message**.
    
    ![Reps can click Insert Message to send it to the customer.](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_dynamic_whatsapp_flow_insert_message_component_in_console.png)
    
    The service rep can then send the message to the customer.

#### See Also

- [_Trailhead:_ Get Started with Screen Flows](https://trailhead.salesforce.com/content/learn/modules/screen-flows/get-started-with-screen-flows)
- [Create a Form Based on an Apex Class](https://help.salesforce.com/s/articleView?id=service.messaging_whatsapp_create_form_apex_class.htm&release=264.0.0&type=5 "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.")