---
schema_version: "1"
id: 7dc48239fc99b86cd547675e9f59777504ca20f3ff8d92c84816b3d55c270ab9
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/android-conversations.md
canonical_url: https://developer.salesforce.com/docs/service/messaging-in-app/guide/android-conversations.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: c6bd79d0a5930c7ddbebbb81d9aafa0f1c64ff04102999049f96a0777293f16a
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://salesforce-async-messaging.github.io/messaging-in-app-android/sdk/core/com.salesforce.android.smi.core/-conversation-client/index.html#962222010%2FFunctions%2F-1357061740).

## 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
val conversationId = UUID.randomUUID()
```

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://salesforce-async-messaging.github.io/messaging-in-app-android/sdk/core/com.salesforce.android.smi.core/-conversation-client/index.html#962222010%2FFunctions%2F-1357061740) 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://salesforce-async-messaging.github.io/messaging-in-app-android/sdk/core/com.salesforce.android.smi.core/-conversation-client/index.html#962222010%2FFunctions%2F-1357061740) 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-android/sdk/core/com.salesforce.android.smi.core/-conversation-client/index.html) ([Core SDK](https://developer.salesforce.com/docs/service/messaging-in-app/guide/android-core-sdk.html)), or create an Interface view ([UI SDK](https://developer.salesforce.com/docs/service/messaging-in-app/guide/android-ui-sdk.html)).

### Close a Conversation

To close a conversation, call the [closeConversation](https://salesforce-async-messaging.github.io/messaging-in-app-android/sdk/core/com.salesforce.android.smi.core/-conversation-client/close-conversation.html) method on the [ConversationClient](https://salesforce-async-messaging.github.io/messaging-in-app-android/sdk/core/com.salesforce.android.smi.core/-conversation-client/index.html), or call the [closeConversation](https://salesforce-async-messaging.github.io/messaging-in-app-android/sdk/core/com.salesforce.android.smi.core/-core-client/index.html#913276732%2FFunctions%2F-1357061740) method on the [CoreClient](https://salesforce-async-messaging.github.io/messaging-in-app-android/sdk/core/com.salesforce.android.smi.core/-core-client/index.html).

Using `ConversationClient`:

```
conversationClient.closeConversation()
```

Using `CoreClient`:

```
let conversationId = <conversationId of conversation to close>
coreClient.closeConversation(conversationId)

```

### Query a Conversation

To query a conversation, refer to the [Conversation List](https://developer.salesforce.com/docs/service/messaging-in-app/guide/android-conversation-lists.html) documentation for query examples and pagination details.
