Show Pre-Chat Fields to User

Before a chat session begins, you can request that the user enter pre-chat fields that are sent to the agent at the start of the session.

The legacy chat product is scheduled for retirement on February 14, 2026, and is in maintenance mode until then. During this phase, you can continue to use chat, but we no longer recommend that you implement new chat channels. To avoid service interruptions to your customers, migrate to Messaging for In-App and Web before that date. Messaging offers many of the chat features that you love plus asynchronous conversations that can be picked back up at any time. Learn about chat retirement in Help.

To create pre-chat fields in your app, instantiate ChatUserData objects during session configuration and then pass the pre-chat info to your ChatConfiguration builder.

  1. Create a -derived object for each pre-chat field. Use the subclass PreChatTextInputField for string fields, the subclass PreChatPickListField for picklists, and you can directly use ChatUserData for fields that don’t require any user input at all. For fields that require user interaction, specify the display label and the label that the agent sees. You can also specify other characteristics, such as whether the field is required and what type of text field it is. When building the input field object, the first string is what the user sees on the device and the second string is what the agent sees in the transcript.

    In Java:

    In Kotlin:

  2. (Optional) Create a list of ChatEntity objects to associate pre-chat fields with fields from a record in your org.

    Pre-chat fields are always sent to the agent at the start of the session. But if you want to fill in fields of a particular record, instantiate a ChatEntity for each Salesforce object (for example, Case or Contact) and add a ChatEntityField for each field association within that Salesforce object (for example, Subject or LastName). After you’ve built your ChatEntity objects, pass them to your ChatConfiguration builder using the chatEntities method.

    To learn more, see Create or Update Salesforce Records from a Chat Session.

  3. Pass the pre-chat info to your ChatConfiguration builder using the chatUserData method.

    In Java:

    In Kotlin:

    From here, you can start the chat session normally.

    In Java:

    In Kotlin:

With this code, the user sees the following pre-chat UI in their mobile app.

Pre-chat UI on app

And the agent sees the following UI from the console.

Pre-chat UI on console