> 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/flow/tutorials/components/record-grid/send-edited-record-grid-rows-to-apex-or-a-decision.md).

# Send Edited Record Grid Rows to Apex or a Decision

Use what users changed in a Record Grid after the screen: skip a step when nothing changed, loop over the edited deals, or pass them to an Apex action.

Once the sales manager has adjusted the three deals, the flow can act on what she changed. It can skip the approval request when she changed nothing, collect the deals she moved to Negotiation/Review, or hand the edits to an Apex class that recalculates the discount. Record Grid writes her edits to three output variables each time she clicks **Save**.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FMUoGHbUGZo2brT7TBkid%2Frecord-grid-send-edited-record-grid-rows-to-apex-or-a-decision-result.png?alt=media" alt="Flow Builder canvas with a Deal Comparison screen followed by an Assignment that counts the edited deals, a Decision, a Loop over the edited deals and an Apex action"><figcaption><p>After the screen, the flow counts the edited deals, branches, loops over them and calls Apex.</p></figcaption></figure>

## Before you start

* An editable Record Grid on Opportunity records, with at least one row marked **Editable**. [Edit and save values in a Record Grid](https://docs.avonnicomponents.com/flow/tutorials/components/record-grid/edit-and-save-values-in-a-record-grid.md) sets up the editing and the **Save** interaction.
* For the Apex step only: an invocable Apex class, written and deployed by a developer.

## The three output variables

| Output variable            | Type                                 | What it holds                                                                                                        |
| -------------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
| **Edited Rows**            | Record collection (Opportunity here) | One record per edited deal, with its Id and only the fields that changed.                                            |
| **Edited Rows Full Data**  | Record collection (Opportunity here) | The same records with every value the grid loaded, edits included.                                                   |
| **Edited Rows Serialized** | Text                                 | **Edited Rows** as a JSON array: one object per edited deal, with `Id` and the changed fields under their API names. |

When they are written:

* Every time the user clicks **Save** in the grid footer. Each **Save** lists every deal edited since the screen opened, not only the latest changes.
* **Cancel** writes nothing. The outputs keep the values of the last **Save**, and stay empty if the user never saved.
* They are written as soon as the user clicks **Save**, before **Update Record(s)** returns. If that save fails, they still hold what the user entered.

## Steps

{% stepper %}
{% step %}

### Make sure the user saves before leaving the screen

The outputs are filled only by **Save**. Wire the grid so that a successful save moves the flow to the next screen (**Flow Navigation** under **On Success** of **Update Record(s)**), as shown in [Edit and save values in a Record Grid](https://docs.avonnicomponents.com/flow/tutorials/components/record-grid/edit-and-save-values-in-a-record-grid.md).
{% endstep %}

{% step %}

### Count the edited deals

After the screen, add an **Assignment** element:

* **Variable**: a new Number variable, `editedDealCount`, with 0 decimal places.
* **Operator**: **Equals Count**.
* **Value**: the Record Grid's **Edited Rows** (in the resource picker, open the grid's API name, `Deal_Grid`, then pick **Edited Rows**).
  {% endstep %}

{% step %}

### Branch on whether anything changed

Add a **Decision** element with an outcome named **Deals Changed**: `editedDealCount` **Greater Than** `0`. The default outcome is the path where the manager changed nothing, so the flow can skip the approval step there.
{% endstep %}

{% step %}

### Loop over the edited deals

On the **Deals Changed** path, add a **Loop** on **Edited Rows Full Data**. Inside it, a **Decision** tests the current deal, for example `StageName` **Equals** `Negotiation/Review`, and an **Assignment** adds the matching deals to a collection for the approval request.

Loop on **Edited Rows Full Data** here, not **Edited Rows**: in **Edited Rows**, a field the manager did not change is empty, so a test on Stage fails for a deal where she changed only the Amount.
{% endstep %}

{% step %}

### Pass the edits to an Apex action

Add an **Action** element and pick the Apex action. Map its input to **Edited Rows** when the class only needs what changed, or to **Edited Rows Full Data** when it needs the whole record. The developer's class receives the records like this:

```apex
public with sharing class DealGridChanges {
    @InvocableMethod(label='Process Deal Grid Changes')
    public static void process(List<List<Opportunity>> editedDeals) {
        for (List<Opportunity> deals : editedDeals) {
            for (Opportunity deal : deals) {
                // deal.Id is set, plus the fields the user edited
            }
        }
    }
}
```

Use **Edited Rows Serialized** when the destination takes text instead of records: a Long Text Area field that keeps an audit trail of the edits, or an action that sends them to another system.
{% endstep %}

{% step %}

### Save and test

Debug the flow.

1. Change the Amount of one deal and click **Save**. On the next screen, the debug details show `editedDealCount` at `1` and the flow takes **Deals Changed**.
2. Restart, change a value, click **Cancel**, then **Next**. `editedDealCount` is `0` and the flow takes the default outcome.
   {% endstep %}
   {% endstepper %}

{% hint style="info" %}
To save the records after the screen instead of inside the grid, leave **Update Record(s)** out of the **Save** interaction and add an **Update Records** element on **Edited Rows**. Since **Edited Rows** carries only the changed fields, only those fields are updated. The user then has to click **Save** in the grid footer before **Next**.
{% endhint %}

## Troubleshooting

<details>

<summary>Edited Rows is empty after the screen</summary>

The user left the screen without clicking **Save** in the grid footer, or clicked **Cancel**. The flow's own **Next** button does not save the grid. Wire **Flow Navigation** under **On Success** (step 1) so a save moves the screen on.

</details>

<details>

<summary>A field is blank in Edited Rows</summary>

**Edited Rows** carries only the fields the user changed. Read **Edited Rows Full Data** when you need the other values.

</details>

<details>

<summary>Edited Rows lists a deal the user did not change in the last save</summary>

Each **Save** reports every deal edited since the screen opened. A deal saved in an earlier click is still in the list.

</details>

## Related tutorials

* [Edit and save values in a Record Grid](https://docs.avonnicomponents.com/flow/tutorials/components/record-grid/edit-and-save-values-in-a-record-grid.md): set up the editing and the **Save** interaction this page reads from.
* [Compare records side by side with Record Grid](https://docs.avonnicomponents.com/flow/tutorials/components/record-grid/compare-records-side-by-side-with-record-grid.md): build the grid and its Get Records.
* [Implementing a bulk edit on the Data Table](https://docs.avonnicomponents.com/flow/tutorials/projects/implementing-a-bulk-edit-on-the-data-table.md): edited Data Table records handed to a second flow and an Avonni Apex action.


---

# 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/flow/tutorials/components/record-grid/send-edited-record-grid-rows-to-apex-or-a-decision.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.
