# Apex SDK for Slack Components

These components are specific to the Apex SDK and don't have Slack block equivalents.

## Date Time Picker

Available in: [Surface components](/docs/platform/salesforce-slack-sdk/guide/surface.md)

Select a date from a calendar and select a time.

![Datetime Picker Example](https://a.sfdcstatic.com/developer-website/sfdocs/salesforce-slack-sdk/media/datetimepicker_standard.png)

The date time picker component is a unique type of component; it isn't a surface, layout component, or element.

**Examples**

This example shows a date time picker with a selected date and time.

```yaml
components:
  - definition: datetimepicker
    name: "exampleDatetimepickerId"
    properties:
      label:
        date: "Example date"
        time: "Example time"
      value: "2021-04-01T09:00"
      placeholder: "Enter a date & time"
      name: "exampleDatetimepickerName"
```

This example shows various ways to use a date time picker.

```yaml
description: "Example usage of the datetimepicker component"
components:
  - definition: modal
    properties:
      title: "Datetimepicker Example"
      submitLabel: "Submit"
      closeLabel: "Close"
    components:
      - definition: section
        properties:
          text: "Datetimepicker with required properties only"
      - definition: datetimepicker
        name: "exampleDatetimepickerId"
        properties:
          label:
            date:
              text: "Pick a date with a smile :smile:"
              emoji: true
            time:
              text: "Pick a time"
              emoji: false
          name: "exampleDatetimepickerName"
      - definition: divider
      - definition: section
        properties:
          text: "Datetimepicker with placeholder"
      - definition: datetimepicker
        name: "exampleDatetimepickerPlaceholderId"
        properties:
          label: "Pick a date & time"
          name: "exampleDatetimepickerPlaceholderName"
          placeholder: "Provide a datetime"
      - definition: divider
      - definition: section
        properties:
          text: "Datetimepicker with confirm dialog"
      - definition: datetimepicker
        name: "exampleDatetimepickerConfirmId"
        properties:
          label:
            date: "Pick a date"
            time: "Pick a time"
          name: "exampleDatetimepickerConfirmName"
          confirm:
            title: "Confirm selection"
            text: "Please confirm the selection"
            confirm: "Confirm"
            deny: "Cancel"
            style: "primary"
      - definition: datetimepicker
        name: "exampleDatetimepickerRequiredId"
        properties:
          label:
            date: "Pick a date (required)"
            time: "Pick a time (required)"
          required: true
          name: "exampleDatetimepickerRequiredName"
```

**Keys**

| Key                      | Type                                                                                                                                                                      | Required | Description                                                                                                                                                |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `definition`             | String                                                                                                                                                                    | Yes      | The value must be `datetimepicker`.                                                                                                                        |
| `properties`             | Object                                                                                                                                                                    | Yes      | The component's properties.                                                                                                                                |
| `properties.label`       | String, [Plain Text](/docs/platform/salesforce-slack-sdk/guide/composition.md#plain-text), [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md), Object | Yes      | An object containing the labels for the date time picker, or a label for the date time picker.                                                             |
| `properties.label.date`  | String, [Plain Text](/docs/platform/salesforce-slack-sdk/guide/composition.md#plain-text), [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md)         | No       | A label for the date input of the date time picker.                                                                                                        |
| `properties.label.time`  | String, [Plain Text](/docs/platform/salesforce-slack-sdk/guide/composition.md#plain-text), [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md)         | No       | A label for the time input of the date time picker.                                                                                                        |
| `properties.value`       | String, [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md)                                                                                            | No       | The initial time that's selected when the date time picker is loaded in the format `YYYY-MM-DDThh:mm`. The time zone is local to the Slack user client.    |
| `properties.required`    | Boolean, [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md)                                                                                           | No       | If `true`, the form can't be submitted when either values in the date time component are empty. The default value is `false`.                              |
| `properties.placeholder` | String, [Plain Text](/docs/platform/salesforce-slack-sdk/guide/composition.md#plain-text), [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md)         | No       | Text used as a placeholder when the `value` is empty.                                                                                                      |
| `properties.name`        | String, [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md)                                                                                            | Yes      | A name applied to the date time picker. The name is used to retrieve the value on submission. If not specified, a name is automatically generated for you. |
| `properties.confirm`     | [Confirm](/docs/platform/salesforce-slack-sdk/guide/composition.md#confirm), [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md)                       | No       | A confirmation dialog to display after a date/time is selected.                                                                                            |
| `name`                   | String, [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md)                                                                                            | No       | The name to uniquely identify this component within the view.                                                                                              |

## Field

Available in: [Surface components](/docs/platform/salesforce-slack-sdk/guide/surface.md)

:::warning
This component has been deprecated. We recommend that you use a [section](/docs/platform/salesforce-slack-sdk/guide/layout.md#section) layout component and render the field name and value using [mrkdwn](/docs/platform/salesforce-slack-sdk/guide/composition.md#mrkdwn) instead.
:::

Add a field-value pair to your view. A field is an [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md) that references a value from a data provider.

The field component is a unique type of component; it isn't a surface, layout component, or element.

**Example**

```yaml
components:
  - definition: field
    properties:
      label: "Name"
      field: "{! record.Name }" # 'record' references a value from a data provider
```

**Keys**

| Key                          | Type                                                                            | Required | Description                                                                                                                                                                                                                                                              |
| ---------------------------- | ------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `definition`                 | String                                                                          | Yes      | The value must be `field`.                                                                                                                                                                                                                                               |
| `properties`                 | Object                                                                          | Yes      | The field's properties.                                                                                                                                                                                                                                                  |
| `properties.label`           | String, [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md)  | Yes      | The label for the field. This value is interpreted as [Mrkdwn](/docs/platform/salesforce-slack-sdk/guide/composition.md#mrkdwn).                                                                                                                                         |
| `properties.field`           | String, [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md)  | Yes      | An expression referencing the field on a record. This value is interpreted as [Mrkdwn](/docs/platform/salesforce-slack-sdk/guide/composition.md#mrkdwn).                                                                                                                 |
| `properties.verbatim`        | Boolean, [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md) | No       | When set to `false`, Slack detects and parses certain values like links in markdown. The default value is `true`. To turn on automatic parsing, set this key to `false`. See [Mrkdwn](/docs/platform/salesforce-slack-sdk/guide/composition.md#mrkdwn) for more details. |
| `properties.disableEncoding` | Boolean, [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md) | No       | An optional parameter that disables encoding for control characters in [Mrkdwn](/docs/platform/salesforce-slack-sdk/guide/composition.md#mrkdwn).                                                                                                                        |

## Iteration

Available in: [Surface components](/docs/platform/salesforce-slack-sdk/guide/surface.md)
Operates on: [Layout components](/docs/platform/salesforce-slack-sdk/guide/layout.md)

To iterate over data in a view, use the iteration component. The iteration component is a unique type of component; it isn't a surface component, layout component, or element component.

The iteration component can contain only layout components. It uses the specified components as a template to display data for each item in a data set.

**Examples**

This example iterates over a list of records from a data provider.

```yaml
components:
  - definition: iteration
    properties:
      foreach: "{! records }" # where 'records' references a value from a data provider
      foritem: "record"
    components:
      - definition: text
        text: "{! record.Name }"
```

This example iterates over a list of commands.

```yaml
description: "A component for the help command that displays a list of available commands."
schema:
  properties:
    commands:
      type: List
      required: true
components:
  - definition: message
    properties:
      text: "List of commands"
    components:
      - definition: section
        properties:
          text: "Here are the available commands for this app"
      - definition: iteration
        properties:
          foreach: "{!view.properties.commands}"
          foritem: "command"
        components:
          - definition: divider
          - definition: section
            properties:
              text:
                text: "*Command*: `{!command.commandName}`"
                type: "mrkdwn"
              fields:
                - text: "*Title*: {!command.title}"
                  type: "mrkdwn"
                - text: "*Description*: {!command.description}"
                  type: "mrkdwn"
```

This example uses a simple list and a list of maps that are passed into a view.

```yaml
description: "This displays a simple list and list of maps passed into a view to be used in an iteration"
schema:
  properties:
    names:
      type: list
      defaultValue:
        - Assam
        - Chai
        - Earl Grey
        - Green Tea
        - Matcha
        - Oolong
    others:
      type: list
      defaultValue:
        - name: Chamomile
        - name: Darjeeling
        - name: Peppermint
components:
  - definition: modal
    properties:
      title: Popular Tea
    components:
      - definition: iteration
        properties:
          foreach: "{!view.properties.names}"
          foritem: "name"
        components:
          - definition: section
            properties:
              text: "{!name}"
      - definition: divider # distinction between "cards"
      - definition: section
        properties:
          text: "More fancy tea variety:"
      - definition: iteration
        properties:
          foreach: "{!view.properties.others}"
          foritem: "tea"
        components:
          - definition: section
            properties:
              text: "{!tea.name}"
```

**Keys**

| Key                  | Type                                                                   | Required | Description                                                         |
| -------------------- | ---------------------------------------------------------------------- | -------- | ------------------------------------------------------------------- |
| `definition`         | String                                                                 | Yes      | The value must be `iteration`.                                      |
| `properties`         | Object                                                                 | Yes      | The component's properties.                                         |
| `properties.foreach` | [Expression](/docs/platform/salesforce-slack-sdk/guide/expressions.md) | Yes      | The list to iterate over.                                           |
| `properties.foritem` | String                                                                 | Yes      | Used to refer to the current item in the array of child components. |
| `components`         | Array                                                                  | No       | An array of child components to render inside the iteration.        |
