# How to create Collection Variables for StartDateTime and EndDateTime

{% hint style="info" %}
This tutorial is currently a work in progress and provides you with a foundational approach for handling **`StartDateTime`** and **`EndDateTime`** collection variables in Salesforce's Event object using Flow Builder. We are expanding this tutorial to include a specific use case integrating with the [Avonni Date Time Picker](https://docs.avonnicomponents.com/flow/flow-components/date-time-picker) component. Stay tuned for updates!
{% endhint %}

## Introduction:

This tutorial walks you through the steps of using Salesforce Flow Builder to create collection variables for **`StartDateTime`** and **`EndDateTime`** from the Event object in Salesforce. This technique allows you to dynamically manipulate or assess these date-time ranges for various use cases, such as populating date-time picker components, running analytics, or setting automated reminders.

***

## Step 1: Initialize Variables

**Why This Step:**

Initializing variables is essential for setting the groundwork. These variables will store date-time data from Salesforce's Event object.

**Actions in Flow Builder:**

* Click on "Manager" to go to the variable management screen.
* Create four variables: **`StartDateTimeCollection`**, **`EndDateTimeCollection`**, **`TempStartDateTime`**, and **`TempEndDateTime`**.
* Set their Data Types to DateTime.
* For **`StartDateTimeCollection`** and **`EndDateTimeCollection`**, check the "Allow multiple values" box.

***

## Step 2: Get Records (Fetch Events)

**Why This Step:**

To collect date-time data, you must query Salesforce's Event object to fetch relevant records.

**Actions in Flow Builder:**

* Drag and drop a "**Get Records**" element onto the canvas.
* Choose the "**Event**" object as the target object.
* Set the filters to fetch records as per your requirement.
* Save these records into a new variable, name it **`TempEvents`** (Allow multiple values)

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FA4rizIs5p2oV32P0WTzQ%2F2023-08-27_20-12-05.png?alt=media&#x26;token=eaa32ec5-237c-402d-b3d6-80949a71fbd0" alt=""><figcaption></figcaption></figure>

* Store the **`StartDateTime`** and **`EndDateTime`** fields.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FKlVGygJmTbcUOyhPHVyT%2F2023-08-27_20-13-19.png?alt=media&#x26;token=242bc000-74e5-41b4-94b4-c9a960c19648" alt=""><figcaption></figcaption></figure>

***

## Step 3: Loop Through Events

**Why This Step:**

A loop enables you to process each event one by one, extracting its **`StartDateTime`** and **`EndDateTime`**.

**Actions in Flow Builder:**

* Drag and drop a "**Loop**" element onto the canvas.
* Connect this Loop to the "Get Records" element.
* Set **`TempEvents`** as the collection variable for the loop.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FtaWzbb9aytaDc0ge26SD%2F2023-08-27_20-27-03.png?alt=media&#x26;token=6ee32b5a-a62b-4cea-89f0-5996811e9b68" alt=""><figcaption></figcaption></figure>

***

## Step 4: Assign DateTimes to Temp Variables (Inside Loop)

**Why This Step:**

You need temporary variables to process each event's individually **`StartDateTime`** and **`EndDateTime`**.

**Actions in Flow Builder:**

* Inside the loop, drag and drop an "Assignment" element.
* Assign **`StartDateTime`** from **`TempEvents`** to **`TempStartDateTime`**.
* Similarly, assign **`EndDateTime`** from **`TempEvents`** to **`TempEndDateTime`**.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FF5vXq4NKbtQIaxyvqqql%2F2023-08-27_20-16-18.png?alt=media&#x26;token=1877f731-3f73-4daf-898d-49cfb69ce2a8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2F8cSMHDAVWLHfcnayfUUf%2F2023-08-27_20-17-39%20(1).gif?alt=media&#x26;token=f85355a6-01d0-4395-b220-3502ffe7f6fa" alt=""><figcaption></figcaption></figure>

***

## Step 5: Add DateTimes to Collection Variables (Inside Loop)

**Why This Step:**

The collection variables are where you'll store each event's **`StartDateTime`** and **`EndDateTime`**, which can later be used for multiple purposes.

**Actions in Flow Builder:**

* Inside the loop, add another "Assignment" element.
* Use this to **add** **`TempStartDateTime`** to **`StartDateTimeCollection`**.
* Do the same for **`TempEndDateTime`** and **`EndDateTimeCollection`**.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FzqnCeIpM8DoO3boLlWTi%2F2023-08-27_20-21-22.png?alt=media&#x26;token=8153fa61-2885-4bc0-b68c-0ff3d090fb37" alt=""><figcaption></figcaption></figure>

***

## Step 6: Close Loop

**Why This Step:**

The loop must be closed to finalize the collection variables, making them ready for use in downstream operations.

**Actions in Flow Builder:**

* Drag and drop a "Loop End" element to the canvas and connect it to signify the end of the loop.

***

By following these steps, you will have successfully created collection variables for **`StartDateTime`** and **`EndDateTime`** in the Event object of Salesforce. These collections can now be used for various operations and manipulations.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FLy6Bn0XE4W9oCyIDR2kv%2F2023-08-27_20-24-06.png?alt=media&#x26;token=aa451cca-4d96-48f7-b7e6-b95aa270afd7" alt=""><figcaption></figcaption></figure>


---

# 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/components/date-time-picker/how-to-create-collection-variables-for-startdatetime-and-enddatetime.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.
