# Why are pre-chat forms essential for gathering customer context before live chat routing?

**Topic:** Service Cloud · **Difficulty:** Medium · **Tags:** Service Cloud, Digital Engagement, Pre-Chat Forms

Read it on the site: https://www.forcechallenges.com/interview-questions/why-are-pre-chat-forms-essential-for-gathering-customer-context-before-live-chat-routing

## Answer

**Basics:** Without pre-chat data, an agent opens a blank chat and spends the first minutes asking for name, email and topic. A pre-chat form asks those up front, can hide fields that the website already knows (logged-in user, order number), and writes them to the session record so routing and case creation are automatic.

**How it works:** Modern setup uses Messaging for In-App and Web with an Embedded Service Deployment: Setup > Embedded Service Deployments > create deployment > Pre-Chat Form. Add visible fields and hidden fields. The data maps to `MessagingSession` and `MessagingEndUser` (and can find or create Contacts). Next, an Omni-Channel flow reads those values and routes using a Route Work action to a queue, skills or an agent. The older channel, legacy Chat (formerly Live Agent), had its own pre-chat form and Chat Buttons; it is being retired in favor of Messaging, so verify dates in release notes.

**Advanced / deep dive:** Hidden pre-chat fields avoid asking logged-in customers for data you already have. Use them to pass the page URL, order Id or product, then use that data in the routing flow (for example set `SkillRequirement` for a product). Pre-chat can also trigger an Einstein Bot (now part of Agentforce/bot offerings) before handing off. Validate input, since pre-chat fields are user-controlled; never treat hidden fields as trusted for security decisions. Map fields to custom fields on MessagingSession so flows and reports can use them. For compliance, add consent text and avoid collecting sensitive data in chat transcripts.

**Code / config example:**
```javascript
// Messaging for In-App and Web: set hidden pre-chat fields from the host page
window.addEventListener('onEmbeddedMessagingReady', () => {
  embeddedservice_bootstrap.prechatAPI.setHiddenPrechatFields({
    Product_Area: 'Billing',
    Order_Number: window.currentOrderId
  });
});
```

**Hidden gotchas & must-remember points:**
- Hidden field names in code must exactly match the pre-chat field definitions in the deployment.
- Pre-chat values are not secure; anyone can alter them in the browser.
- Routing relies on your Omni flow or routing configuration; the form alone does not route.
- Legacy Chat and Messaging use different setup and objects (LiveChatTranscript versus MessagingSession).
- Re-publish the deployment after changing the form, or the website keeps serving the old one.
- Collecting too many required fields increases abandonment.

**Best practice:** Ask only for what routing and the agent need, prefill the rest with hidden fields, and test the complete route from form to agent.

---
Source: ForceChallenges · last updated 2026-11-02
