> 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/save-case-comments.md).

# Save Case Comments from Chat

Add an Avonni Chat to a Salesforce Case page, display the current case's internal comments, and let support agents save new comments from the thread.

Give support agents a place to read and post internal case notes on the Case record page. Avonni Chat displays the notes and takes new input. A Create Record interaction saves the input as a Salesforce Case Comment.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FOzTEUaILKLO8TRmtjHhd%2Fchat-save-case-comments-compact.jpg?alt=media" alt="Case record page with two internal comments and a Post Comment button in Avonni Chat." width="386"><figcaption><p>The new internal comment appears under the original note.</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%2FMSnJlwwR4S2L9IkAWelp%2Fchat-save-case-comments-result.jpg?alt=media)

## Before you start

* Use a sandbox with Avonni Dynamic Components installed and access to build a component and assign a Case record page. Confirm that your test agent can use Dynamic Components and read and create comments on the test cases.
* Create two test cases named `Label printer offline` and `Packing station slow`. In Salesforce's Case Comments related list, add an internal comment to the first case: `Printer stopped after the restart.` On the same test case, add a published comment: `The support team is investigating.` Keep the second case empty for the first test.

## Build the chat

{% stepper %}
{% step %}

### Create a component for Case

1. Open **Dynamic Components**, click **New Component**, and select **Create Blank Component**.
2. Drag **Chat** from the component library onto the canvas. Click **Save**.
3. Set the component label to `Internal Case Comments` and set **Target Page Object** to **Case**. Save the component.
   {% endstep %}

{% step %}

### Load only the current case's internal comments

1. Select Chat on the canvas. In **Properties**, set **Data Source** to **Query** and click **Create a query**. Under **Object API Name**, turn on **All Objects**, search for `Case` and select **Case Comment** (`CaseComment`).
2. Filter `ParentId` by the page record. Switch the value to **Mapped** and select **$Component** > **RecordId** (`{!$Component.RecordId}`).
3. Add a second filter for **Published** (`IsPublished`). Use **Equals** and leave **Value** unchecked. Keep **All Conditions Are Met** and save the query.
4. In **Data Mappings**, set **Content** to **Body** (`CommentBody`) and leave **Date** on **Created Date**. Leave **Key Field** on the record ID.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FxISTa8c9O3LShDV3Uu4o%2Fchat-save-case-comments-query.jpg?alt=media" alt="Case Comment query with Parent ID mapped to the current Case and Published set to false." width="550"><figcaption><p>The query selects internal comments on the current case.</p></figcaption></figure>
{% endstep %}

{% step %}

### Save what the agent posts

1. Under **Publisher**, set **Mode** to **Plain** and **Publish Button Label** to `Post Comment`.
2. Under **Interactions**, add **Create Record** to **Publish a New Message**. For **Record Variable**, select **Enter Record Data Manually**. Under **Object API Name**, turn on **All Objects** and choose **Case Comment**.
3. In **Data Mapping**, set **Parent ID** to **Custom** and enter `{!$Component.RecordId}`. Map **Body** to **Message: Content**. For **Published**, toggle **Mapped** to open the resource picker and choose **Global Constants** > **False**.
4. Under **On Success**, add **Refresh Query** and select **Current Component**. This reloads the thread after Salesforce saves the comment.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FKSiOUK7i1rdcbgKmniyH%2Fchat-save-case-comments-create.jpg?alt=media" alt="Create Record mappings for Parent ID, Body and Published, with Message: Content selected for Body." width="320"><figcaption><p>The publish interaction saves the message as an internal Case Comment.</p></figcaption></figure>
{% endstep %}

{% step %}

### Add Chat to the test page

1. Save and activate the Dynamic Component.
2. Open a test case. From the **Setup** gear on the record page, choose **Edit Page** to open Lightning App Builder.
3. Drag **AX - Dynamic Component** onto the test page and select `Internal Case Comments`. Save and assign the page to your test app or profile.
   {% endstep %}

{% step %}

### Save a comment and check the record

1. Open `Label printer offline` on your activated page. Confirm the internal comment appears and the published comment stays out of Chat. Enter `Replacement cable requested.` and click **Post Comment**. Confirm it appears once, below the original note, without reloading the page.
2. Check the Case Comments related list in a separate tab. Confirm the published comment is present there. Confirm one new comment with the posted body belongs to `Label printer offline` and is marked internal. Reload the page with Chat and check that it still appears once.
3. Open `Packing station slow`. Check that the chat shows its empty state. Add a different internal comment using the standard Case Comments related list, then reload the page. Confirm the second case's comment appears only on that case.
   {% endstep %}
   {% endstepper %}

## Troubleshooting

<details>

<summary>The comment saves but the thread stays the same</summary>

Check **Refresh Query** under **On Success** and its target. If the comment still stays hidden after reloading, compare its parent case and publish flag with both query filters.

</details>

<details>

<summary>The new comment never appears in Case Comments</summary>

Check that **Publish a New Message** runs **Create Record** and that the test user can create the comment. Check that the action gets the current Case ID and the text from the publisher.

</details>

## Related tutorials

* [Keep replies and pins after reload](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/chat/persist-replies-and-pins.md) adds quoted replies and pins using a custom message object.
* [Chat reference](https://docs.avonnicomponents.com/dynamic-components/components/chat.md) lists the data mappings, publisher settings, and interactions.


---

# 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/save-case-comments.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.
