# Flow Grids

Flow Grids GridMate provides lightning components to deal with data tables in flows. We provide components to view/select and edit a collection of records.&#x20;

In this tutorial, we will setup a flow to select a list of contact  and add them as list of contact roles with the ability to set the role of each contact from the flow.

![Mass Add Contact Role Flow](https://4046919449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MEsSbGy_U_OhthKUpxu%2Fuploads%2FZ5NXJ7kV1dZX4cFUL26C%2FScreenshot%202021-12-12%20at%2013.34.50.png?alt=media\&token=635331ee-c8e2-4dc9-b0c4-f77b7300ff1c)

This flow is launched from an **Opportunity** record page by passing the current record Id. We get the opportunity details using the passed **recordId**.&#x20;

The opportunity record is used to get the opportunity account contacts. The list of contacts is then converted to a JSON collection and passed to **GM - Flow View Grid** component.

![](https://4046919449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MEsSbGy_U_OhthKUpxu%2Fuploads%2FpUEqggURBtpseTWj30SM%2FScreenshot%202021-12-12%20at%2013.42.50.png?alt=media\&token=4b21d06a-5f79-4a9f-af2b-2b12ee81dc2d)

**GM - Flow View Grid** requires at least the following attributes:

* **API Name**: the API name of the component in the flow.
* **Related Object Name**: the API name of the displayed object (Contact).
* **FieldSet Nadme**: the API name of the fieldSet of the displayed object.
* **Custom Label**: the label of the grid. If this property is empty, the fieldSet label will be used.
* **Candidates**: JSON collection of records to display. JSON collection conversion from an SObject collection is handled by **GM - Json from Collection** Apex action. This action is a part of GridMate package.
* **Filter**:  JSON expression to filter the records. This option doesn’t require a **Get Records** to filter the records. We recommend using **candidates** option only if the filtering logic is too complex.

**Select Contacts** screen displays a grid where the user can see the records and select a subset to add as an **Opportunity Contact Role.**&#x20;

![](https://4046919449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MEsSbGy_U_OhthKUpxu%2Fuploads%2FDmuAcTTJquaDhBH970q9%2FScreenshot%202021-12-12%20at%2014.35.20.png?alt=media\&token=57430ff2-7d92-4069-aa15-904a2cd2315f)

{% hint style="info" %}
When a flow contains more than one screen, to save the selected records, they should be saved in flow variable and passed back to **GM - Flow View Grid.** To achieve this, you should follow the steps below:

* Create a collection of string : **contactIdList**
* On the component properties, go Advanced and check Manually assign varaibles
* Set  **22.Selected Id(s)** to contactIdList
* Check Use values from when the user last visited this scree under Revisited Screen Values section.
  {% endhint %}

<figure><img src="https://4046919449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MEsSbGy_U_OhthKUpxu%2Fuploads%2Fa43d1nSACzu2rme3pej7%2FScreenshot%202023-07-09%20at%2011.08.53.png?alt=media&#x26;token=d71fe9ad-3761-4209-afde-cf0e15456c03" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4046919449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MEsSbGy_U_OhthKUpxu%2Fuploads%2F1Vuby3FrRN2OnZslMXkv%2FScreenshot%202023-07-09%20at%2011.09.11.png?alt=media&#x26;token=6a312cf3-e025-4580-a560-1a1cc70776e4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4046919449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MEsSbGy_U_OhthKUpxu%2Fuploads%2FdxKnywhpDV5koYZszR76%2FScreenshot%202023-07-09%20at%2011.09.21.png?alt=media&#x26;token=b7ac7bce-1a58-48f4-859f-4741d8f48773" alt=""><figcaption></figcaption></figure>

The list of selected records is converted to an SObject collection. SObject collection conversion from an JSON collection is handled by **GM - Collection from Json** Apex action. This action is a part of GridMate package.

We iterate on the contact collection to create the corresponding opportunity contact roles and save them into Salesforce.

The last step of our flow is to be able to edit the contact roles or completely delete them. Editing a collection of records is handled by **GM - Flow Edit Grid** component.

![](https://4046919449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MEsSbGy_U_OhthKUpxu%2Fuploads%2FmnKA6YVjvPzXWdU7PdWg%2FScreenshot%202021-12-12%20at%2014.44.25.png?alt=media\&token=fa10a57c-7cc7-4403-98d8-9079207d7df3)

**GM - Flow Edit Grid** requires at least the following attributes:

* **API Name**: the API name of the component in the flow.
* **Related Object Name**: the API name of the displayed object (OpportunityContactRole).
* **FieldSet Nadme**: the API name of the fieldSet of the displayed object.
* **Custom Label**: the label of the grid. If this property is empty, the fieldSet label will be used.
* **Candidates**: JSON collection of records to display if the filter property is not used.
* **Filter**:  JSON expression to filter the records. We recommend using a formula to build the expression as below.

![](https://4046919449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MEsSbGy_U_OhthKUpxu%2Fuploads%2Fqbu8HHkT4HRO8pCPPVpz%2FScreenshot%202021-12-12%20at%2014.47.19.png?alt=media\&token=85485f67-fcc5-44b2-a97b-302671a9157f)

* **Save Records**: Set this property to True if you want to save the records to Salesforce once the user hits **Next**/**Finish**. If not, you can get the updated records from the component and do the update using an **Update Records** component.

{% hint style="warning" %}
**GM - Flow Edit Grid** implements a flow action bar, thus the component should be in the bottom of the screen and standard header should be hidden.
{% endhint %}

Below is a quick demo of the final version of our flow where the user can smoothly add Opportunity Contact Roles with few clicks!

{% embed url="<https://youtu.be/Dd_MCP__UNw>" %}
**GM - Flow Edit Grid**
{% endembed %}

## Drag To Fill

The **Drag to Fill** feature in the Flow Grid component enhances data entry by allowing users to **quickly apply a single value across multiple cells**. Users can simply enter the value once and drag, similar to traditional spreadsheets.

{% embed url="<https://youtu.be/IzBy450KmJo>" %}
