Create or Update Salesforce Records from a Chat Session

When a chat session begins, you can create or find records within your org and pass this information to the agent. Using this technique, your agent can immediately have all the context they need for an effective chat 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.

Before reading these instructions, review Show Pre-Chat Fields to User to understand how to create pre-chat fields.

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 an SCSPrechatEntity for each Salesforce object (for example, Case or Contact) and instantiate an SCSPrechatEntityField for each field association within that Salesforce object (for example, Subject or LastName).

Each pre-chat entity must map to a pre-chat object (SCSPrechatObject, SCSPrechatTextInputObject, or SCSPrechatPickerObject). The label string in this pre-chat object must be identical to the label used in your SCSPrechatEntityField object.

Use the config object’s prechatFields property for the array of your pre-chat objects and the prechatEntities property for the array of your entity objects.

Case creation does not currently work for Omni-Channel routing without a setup change to your org. To resolve this problem, raise a ticket with Salesforce to ensure that Omni-Channel is enabled to create a Case in your org.

This sample code shows how to pass the first and last name to a contact record in your org. This example doesn’t involve user input, but you can use SCSPrechatTextInputObject instead of SCSPrechatObject to allow user input.

In Swift:

In Objective-C:

The SCSPrechatEntity and SCSPrechatEntityField classes give you various configuration settings for mapping fields. For example, if a field doesn’t exist, you can have the SDK create that field. The following code sample illustrates some basic building blocks when creating an SCSPrechatEntity object.

In Swift:

In Objective-C:

See the reference documentation for SCSPrechatEntity and SCSPrechatEntityField. Also refer to Chat REST API Data Types for the Entity and EntityFieldsMaps data types, which define the underlying functionality of these SDK objects.

This code sample adds FirstName, LastName, Email to a Contact record and a Subject field to a Case record.