---
schema_version: "1"
id: dbb19cfd6e9c061366082b1501cbe5c8930d560182cc6f0c7e601b261b4c7b42
title: Manage Conversations
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/messaging-in-app/guides/ios-conversations.md
canonical_url: https://developer.salesforce.com/docs/service/messaging-in-app/guide/ios-conversations.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: d19727fb360ff9649496361c720aa004214c916d8827d3c17c5a81fb18501d38
products:
  - Enhanced In-App Chat
  - Service Cloud Developer Content
---
# Manage Conversations

This document provides implementation guidelines and best practices for developers on how to generate conversation IDs and use these IDs to create, close, and query conversations.

## Conversations

A messaging conversation represents a communication exchange between a messaging user—also known as the customer—and a service rep, an Agentforce agent, an Einstein bot, or a combination of them.

### Lifetime of a Conversation

The lifetime of a conversation is broken down into four stages:

1. **Creation**–A new messaging conversation between a messaging user and a service rep, Agentforce agent, or Einstein bot starts.
2. **Session**–One or more messaging sessions occur within that conversation. Ending a session does not end the conversation. For example, clicking the **End Chat** button ends only the current session; it doesn’t end the conversation. See the [Enhanced Chat and Messaging Glossary](https://help.salesforce.com/s/articleView?id=service.miaw_glossary.htm) for precise definitions.
3. **Closing**–The messaging conversation is explicitly closed. When a conversation is closed, the status of the conversation changes to closed and no new messages can be sent.
4. **Persistence**–The conversation history is preserved, and the historical conversation data can be queried at any time for analysis using the [Conversation Query API](https://developer.salesforce.com/docs/service/messaging-in-app/guide/%3Chttps://salesforce-async-messaging.github.io/messaging-in-app-ios/documentation/smiclientcore/coreclient/conversations(withlimit:sortedbyactivitydirection:completion:)/>).

## Conversation IDs

Each conversation has a unique, randomly-generated ID that persists for the conversation’s entire lifetime and links all messages and participants in that thread.

The Enhanced In-App SDK uses these conversation IDs to track and manage message conversations throughout their entire lifecycle.

A valid conversation ID must be:

- A randomly-generated (version 4\) universally unique identifier (UUID v4).
- Completely independent of business logic or customer data.
- Used only for conversation tracking and management.

Never substitute conversation IDs with customer IDs or any other business identifiers.

### Conversation ID Limitations

Consider the following limitations with conversation IDs:

- Conversation IDs can’t be moved from a staging org to a production org.
- Conversation IDs can’t be transferred between verified and unverified users.
- Conversation IDs created in an unverified session can’t be migrated to another device.
- Conversation IDs are tied to user verification; if the local database or app is deleted, unverified conversations become inaccessible.

### Generate Conversation IDs

The Enhanced In-App SDK can generate UUIDs automatically, or you can manually generate the IDs yourself:

```
// Generate a new UUID for conversation
let conversationId = UUID()
```

Follow these guidelines when generating conversation IDs:

- The conversation ID must be a randomly-generated (version 4\) universally unique identifier (UUID v4)
- The conversation ID must be generated with the system’s UUID mechanism.
- The conversation ID must be unique across all conversations.
- The conversation ID must be stored and managed by your application.

## Manage Conversations

### Persist a Single Conversation

To keep one ongoing conversation, you need:

- A valid and unique conversation ID (UUID).
- Proper initialization of the conversation object.
- Persistent storage for the ID.
- Logic to manage conversation state.

### Manage Multiple Conversations

Use the [Conversation Query API](https://developer.salesforce.com/docs/service/messaging-in-app/guide/%3Chttps://salesforce-async-messaging.github.io/messaging-in-app-ios/documentation/smiclientcore/coreclient/conversations(withlimit:sortedbyactivitydirection:completion:)/>) to access and display multiple conversations. See Conversation Lists for more information.

Follow these best practices when generating conversation IDs:

- Store and retrieve conversation IDs systematically.
- Use pagination for large result sets.
- Implement retries and error handling.
- Cache conversations when appropriate.
- Prefer verified users for multi-conversation workflows.

### Recommended Approach

Consider the following recommended approaches when managing conversations.

**Developer manages conversation IDs**

Follow best practices when managing conversation IDs. Some aspects to consider when managing conversation IDs include:

- Generating and storing the unique conversation ID (UUID).
- Persisting the conversation ID securely (e.g., Keychain / encrypted database).
- Handling the conversation ID’s lifecycle.
- Using verified conversations for anything beyond quick one-offs.

**Developer leverages SDK queries**

Use the Enhanced In-App SDK queries to take full advantage of your conversation data. For example,

- Use the [Conversation Query API](https://developer.salesforce.com/docs/service/messaging-in-app/guide/%3Chttps://salesforce-async-messaging.github.io/messaging-in-app-ios/documentation/smiclientcore/coreclient/conversations(withlimit:sortedbyactivitydirection:completion:)/>) to look up existing conversations.
- Implement robust error handling.
- React to state changes (e.g., closed, archived).

## Implement Conversations

Follow these implementation guidelines to create, close, and query conversations.

### Create a New Conversation

To create a new conversation, build a configuration object and instantiate a [ConversationClient](https://salesforce-async-messaging.github.io/messaging-in-app-ios/documentation/smiclientcore/conversationclient) ([Core SDK](https://developer.salesforce.com/docs/service/messaging-in-app/guide/ios-core-sdk.html)), or create an Interface view ([UI SDK](https://developer.salesforce.com/docs/service/messaging-in-app/guide/ios-ui-sdk.html)).

### Close a Conversation

To close a conversation, call the [closeConversation](https://developer.salesforce.com/docs/service/messaging-in-app/guide/%3Chttps://salesforce-async-messaging.github.io/messaging-in-app-ios/documentation/smiclientcore/conversationclient/closeconversation(completion:)>) method on the [ConversationClient](https://salesforce-async-messaging.github.io/messaging-in-app-ios/documentation/smiclientcore/conversationclient), or call the [closeConversation](https://developer.salesforce.com/docs/service/messaging-in-app/guide/%3Chttps://salesforce-async-messaging.github.io/messaging-in-app-ios/documentation/smiclientcore/coreclient/closeconversation(withidentifier:completion:)>) method on the [CoreClient](https://salesforce-async-messaging.github.io/messaging-in-app-ios/documentation/smiclientcore/coreclient).

Using `ConversationClient`:

```
conversationClient.closeConversation(completion: { error in
})
```

Using `CoreClient`:

```
let conversationId = <conversationId of conversation to close>
coreClient.closeConversation(identifier: conversationId, completion: { error in

})
```

### Query a Conversation

To query a conversation, refer to the [Conversation List](https://developer.salesforce.com/docs/service/messaging-in-app/guide/ios-conversation-lists.html) documentation for query examples and pagination details.
