> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chat/persist-replies-and-pins.md).

# Keep replies and pins after reload

Keep a workaround at the top of an escalation chat and save quoted replies with Avonni Chat, so both are still visible when another agent opens the case.

When a support case changes hands, the next agent needs to find the workaround and see which message each reply answers. Use Avonni Chat to show the quotes and the pinned banner. Store the reply and pin fields on Salesforce message records so the thread survives a reload.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FO87CUDaLsl8GK6zZYRA4%2Fchat-persist-replies-and-pins-compact.jpg?alt=media" alt="Case chat with a pinned printing workaround above a reply quoting the original message." width="386"><figcaption><p>The workaround and quoted reply are still visible after reloading the case.</p></figcaption></figure>

[Open the wider Salesforce capture](https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2F5v58kkZWQBqywU40M4a6%2Fchat-persist-replies-and-pins-result.jpg?alt=media)

## Before you start

* Use a sandbox where you can create a custom object and fields. Use a separate Dynamic Component from [Save Case Comments from Chat](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chat/save-case-comments.md), which stores notes as standard Case Comments.
* Reuse the test cases `Label printer offline` and `Packing station slow`. Give test agents access to the cases and permission to read and create Case Message records. Agents who pin messages need edit access to those records and to the pin field.

## Build the escalation chat

{% stepper %}
{% step %}

### Create the message records

1. In Salesforce, create a custom object named `Case Message` (`Case_Message__c`) with an auto-number record name.
2. Add the four fields below. Make the Case lookup required, and keep the Reply To lookup optional.

| Field                    | Type                        |
| ------------------------ | --------------------------- |
| Case (`Case__c`)         | Lookup to Case              |
| Body (`Body__c`)         | Rich Text Area              |
| Reply To (`Reply_To__c`) | Lookup to Case Message      |
| Pinned (`Pinned__c`)     | Checkbox, default unchecked |

3. On `Label printer offline`, create a message with the body `Print labels from station 2 until the cable arrives.` Leave it unpinned. Keep `Packing station slow` available as a separate test case.
   {% endstep %}

{% step %}

### Map the quote and pin

1. Create a blank Dynamic Component named `Escalation Chat`, with **Case** as the **Target Page Object**. Add **Chat**.
2. Set **Data Source** to **Query** and click **Create a query**. Select **Case Message** and filter its **Case** field by **$Component** > **RecordId** in **Mapped** mode.
3. Under **Data Mappings**, set **Content** to `Body__c` and **Date** to **Created Date**. In **Advanced Options**, set **Key Field** to `Id`, **Reply To** to `Reply_To__c`, and **Pinned** to `Pinned__c`.
4. Turn on **Allow Reply** under **Content**. Under **Pin Messages**, turn on **Can Pin**. Under **Publisher**, keep **Mode** on **Rich** and set **Publish Button Label** to `Send`.

A reply can show a quote when the lookup value matches the **Key Field** of a message loaded in the same thread.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2F1J4vE6ijmHxYp01yeWBg%2Fchat-persist-replies-and-pins-mappings.jpg?alt=media" alt="Chat data mappings with the message Id, reply lookup and pinned checkbox selected." width="320"><figcaption><p>The message ID links each quote to its original message.</p></figcaption></figure>
{% endstep %}

{% step %}

### Save the message and the reply target

1. Add a **Create Record** interaction to **Publish a New Message**. Set **Record Variable** to **Enter Record Data Manually** and **Object API Name** to `Case_Message__c`.
2. Set **Case** to **Custom** and enter `{!$Component.RecordId}`. Map **Body** to **Message: Content**.
3. Map `Reply_To__c` to **Message: Reply To**. This value is empty for a new top-level message.
4. Under **On Success**, add **Refresh Query** for **Current Component**.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FT3P7FcpAE6KV2VgGcgle%2Fchat-persist-replies-and-pins-create.jpg?alt=media" alt="Create Record field mapping from the outgoing message Reply To to the reply lookup." width="320"><figcaption><p>The publish interaction stores the original message ID on the reply.</p></figcaption></figure>
{% endstep %}

{% step %}

### Save each pin change

1. Add **Update Record** to **Pin a Message**. Set **Record Variable** to **Enter Record Data Manually** and toggle **Mapped** next to **Record Id**. Choose **Chat 1** > **Last Pin Toggled - Message sObject** > **Id**.
2. Set the object to **Case Message**. Add a mapping for **Pinned**, toggle **Mapped** and choose **Global Constants** > **True**. Add **Refresh Query** for **Current Component** under **On Success**.
3. Add the same interaction to **Unpin a Message**, with **Pinned** mapped to **Global Constants** > **False**.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fxlg1TpkwnHWykSJpkT7X%2Fchat-persist-replies-and-pins-pin.jpg?alt=media" alt="Update Record settings using the selected message Id and setting Pinned to True." width="320"><figcaption><p>The pin interaction updates the message record selected in Chat.</p></figcaption></figure>
{% endstep %}

{% step %}

### Save and test the record changes

1. Save and activate `Escalation Chat`. In Lightning App Builder, select it in an **AX - Dynamic Component** on your test Case page. Save and assign the page.
2. Open `Label printer offline`. Reply to the workaround with `Station 2 is printing again.` Verify the new bubble quotes the workaround. In the Salesforce Case Message record, confirm **Reply To** points to the workaround record and **Case** points to `Label printer offline`.
3. Pin the workaround. Check the pinned banner and confirm the workaround record's **Pinned** field is checked. Reload the case page and confirm the quote and pin are both still there.
4. Unpin the workaround. Confirm **Pinned** is cleared on its record and the banner no longer shows the workaround after reload. The reply still quotes it.
5. Send a message without choosing a reply target. Check that the new record's **Reply To** field is empty. Open `Packing station slow` to verify that the first case's messages are absent.
   {% endstep %}
   {% endstepper %}

## Troubleshooting

<details>

<summary>The reply saves without a quote</summary>

Open the reply's Case Message record and check its **Reply To** field. If it is empty, check the field mapping in **Publish a New Message**. If it is filled, check that the original message belongs to this case and is loaded by the query.

</details>

<details>

<summary>A pin disappears after reloading</summary>

Check whether **Update Record** changed `Pinned__c` on the selected message. Then confirm that the Chat **Pinned** mapping reads that field and **Can Pin** is enabled.

</details>

## Related tutorials

* [Refresh Chat across sessions](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chat/refresh-chat-across-sessions.md) keeps a second viewer's thread current as new messages arrive.
* [Chat reference](https://docs.avonnicomponents.com/dynamic-components/components/chat.md) explains message identity, pin settings, and interaction outputs.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chat/persist-replies-and-pins.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
