# Configuration tutorial

## How to Build a Self-Updating Data Table in Salesforce with Platform Events

This step-by-step guide walks you through the process of creating a real-time updating Data Table using Avonni, Platform Events, and Salesforce Flows.

By the end, you'll have a Data Table that **automatically refreshes itself**—no manual reloads required—whenever related records are created or updated in Salesforce.

### Overview of What You'll Build

To make this work, you'll set up three things:

1. A **Platform Event** to broadcast data changes
2. A **Record-Triggered Flow** to publish the event
3. A **Screen Flow** with a Data Table that listens and refreshes in real-time

{% stepper %}
{% step %}

#### **Create a Platform Event**

We need a way to signal when a record changes. Platform Events act like a message system, letting us broadcast these changes in real-time

* Go to **`Setup`** and search for **`Platform Events`**.
* Click **`New Platform Event`**.
* Fill in the **`Label`** (e.g., "RecordChangeEvent"), **`Plural Label`**, and the **`API Name`** should auto-populate.
* Set Publish Behavior **to `Publish After Commit`**.
* Click **`Save`**.

  <figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FYza8b03GEjSEulWD9Xmj%2F2024-09-15_09-53-56.png?alt=media&#x26;token=41dc3c4a-ffd3-44e3-8311-e0de6e8d3cb9" alt=""><figcaption></figcaption></figure>

{% endstep %}

{% step %}

#### **Add a Field to the Platform Event**

We’ll use a field to pass the ID of the changed record. This helps the component know *which* data to refresh.

1. Inside your new Platform Event, click **New Field**.
2. Choose **Text** as the data type.
3. Fill in:
   * **Field Label**: Example – `RecordId`
   * The API Field Name will auto-fill.
4. Click **Next**, configure any field options if needed, and click **Save**.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FyvZGLpXWZ9PnkoVTsOKK%2F2024-09-15_09-56-14.png?alt=media&#x26;token=7ac6e276-8745-4333-a90e-ca5e13a1eba7" alt=""><figcaption></figcaption></figure>

{% endstep %}

{% step %}

#### **Create a Trigger Flow**

This Flow sends a Platform Event when a record is created or updated.

1. In **Setup**, search for **Flows** and click **New Flow**.
2. Choose **Record-Triggered Flow**.
3. Configure the flow trigger:
   * **Object**: Choose the object to watch (e.g., `Lead` or `Account`)
   * **Trigger**: Choose `Created`, `Updated`, or both
   * Add **Conditions** if you only want the event triggered in specific cases
4. Click **Done**.

Now add an action to publish the Platform Event:

5. Drag a **Create Records** element to the canvas.
   * **Label**: e.g., `Create Record Change Event`
   * **How to Set Values**: Select `Manually`
   * **Object**: Choose the Platform Event you created (e.g., `RecordChangeEvent__e`)
   * **Field Values**: Set the `RecordId` field to `{!Record.Id}`
6. (Optional) Add a **Decision** node if you want more control over when the event is sent.
7. Click **Activate** to turn on the flow.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FSqUhGDU7FDitZilYBKb4%2F2024-09-15_10-28-25.png?alt=media&#x26;token=c43ae3da-5378-4ee6-b152-bab109e9551c" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### **Create a Screen Flow**

Now we build the actual user interface that listens for the Platform Event and refreshes automatically.

1. In **Setup**, go to **Flows** and click **New Flow**.
2. Choose **Screen Flow**.
3. Add a **Screen** element to the canvas.
4. Drag a **Data Table** component onto the screen.

#### Configure the Data Table:

* **Data Source**: Select `Query`
* **Object**: Choose the object you want to display (e.g., `Account`)

**Configure Real-Time Refresh:**

* In the **Advanced Options** of the Data Table:
  * **Channel Name**: Enter the API name of your Platform Event (e.g., `RecordChangeEvent__e`)
  * **Key Field Name**: Enter the name of the Platform Event field that holds the record ID (`RecordId`)
  * (Optional) **Key Field Value**: Use this if you only want to refresh for one specific record ID

> 💡 Want to understand these settings in detail?\
> See: [Query Refresh EMP Options Explained](https://docs.avonnicomponents.com/flow/tutorials/platform-events/..#query-refresh-emp-settings-explained)

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FUwJ7vlTJa7Egp6f4FQjZ%2F2024-10-01_16-04-01.png?alt=media&#x26;token=cd813ddf-e7f5-485c-b1c8-ceb71580720c" alt=""><figcaption></figcaption></figure>

{% endstep %}

{% step %}

#### **Deploy the Flow**

Click **"Save" and then "Activate"** your Screen Flow.

**Now you have a datatable that updates in real-time whenever the specified records are changed, thanks to the power of Platform Events and Salesforce Flows.**
{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.avonnicomponents.com/flow/tutorials/platform-events/configuration-tutorial.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
