---
schema_version: "1"
id: f05a1dfaf13987856f0d89501677a2a96cedee5e647e90f88fde2c78e393be6b
title: Work with Options
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforce-slack-sdk/apex-slack-sdk/guides/apex_ref/apex_ref_options.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/apex_ref_options.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: d85bc229b378338f3089a86c1c958a8f3be81a1d0265573d40cd9ed251debdf9
products:
  - Apex SDK for Slack (Beta)
---
# Work with Options

Use these Apex classes to implement a [Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#select) component or a data provider specified by the `datasource` key on an [External Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#external-select) component.

**tip:** The [sample app](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/setup-install-app.md) has several examples that use the Select and External Select components.

## Option Class

Creates an option for the [Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#select) or [External Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#external-select) component.

For the External Select component, construct your data using `List<Slack.Option>` and return it using `Slack.OptionDataResponse`.

Alternatively, specify the values or use an expression in the view definition for the [Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#select) or [External Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#external-select) component.

### Usage

Construct `List<Slack.Option>` to build a list of values for the Select component.

```java
public class DataProviderOpportunityLookup {
    private static final String NO_OPPORTUNITY = 'Account has no Opportunity';
    private static final String MISSING_OR_INCORRECT_ACCOUNT_ID = 'Account Id is missing or is incorrect';

    /* Use List<Slack.Option> to retrieve all opportunities by accountId.
    Return result in the format List<String, String> to the view. */
    public static List<Slack.Option> getOpportunitiesByAccount(String accountId) {
        List<Slack.Option> oppOptions;

        if (String.isNotBlank(accountId)) {
            List<Opportunity> opps = queryOpportunities(accountId);
            oppOptions = new List<Slack.Option>();

            if (!opps.isEmpty()) {
                for (Opportunity opp : opps) {
                    Slack.Option oppOption = new Slack.Option(opp.Name, opp.Id);
                    oppOptions.add(oppOption);
                }
            } else {
                oppOptions.add(new Slack.Option(NO_OPPORTUNITY, NO_OPPORTUNITY));
            }
        } else {
            oppOptions = new List<Slack.Option>{ new Slack.Option(MISSING_OR_INCORRECT_ACCOUNT_ID, MISSING_OR_INCORRECT_ACCOUNT_ID) };
            System.debug(MISSING_OR_INCORRECT_ACCOUNT_ID);
        }

        return oppOptions;
    }
}
```

See the [sample app](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/setup-install-app.md) for a full example.

Alternatively, use the `Slack.Option` class to build your option list for the External Select component and return it using `Slack.OptionDataResponse`.

```java
public class DataProviderAccountLookup {
    public static Slack.OptionDataResponse getAccountsByName(String value) {
        List<Account> accounts;
          if (String.isNotBlank(value)) {
              String name = '%' + value + '%';
              accounts = [SELECT Id, Name FROM Account WHERE Name LIKE :name WITH SECURITY_ENFORCED LIMIT 10];
          }

        List<Slack.Option> accountOptions = new List<Slack.Option>();
        if (accounts != null) {
            for (Account account : accounts) {
                Slack.Option option = new Slack.Option(account.Name, account.Id);
                accountOptions.add(option);
            }
        }
        return new Slack.OptionDataResponse(accountOptions);
    }
}

```

### Option Constructor

`Option` has the following constructor.

#### Option(text, value)

Creates an instance of the `Slack.Option` class with the text and value.

**Signature**

```java
public Option(String text, String value)
```

**Parameters**

_text_

Type: String

The text to display on the component.

_value_

Type: String

The value of the option.

### Option Methods

The following are methods for `Option`.

#### getText()

Gets the display text for the component.

**Signature**

```java
public String getText()
```

**Return Type**

Type: String

#### getValue()

Gets the value of the option.

**Signature**

```java
public String getValue()
```

**Return Type**

Type: String

---

## OptionDataResponse Class

The data to return for the [External Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#external-select) component using a `List<Slack.Option>` or `List<Slack.OptionGroup>`.

### Usage

Construct `Slack.OptionDataResponse` with `List<Slack.OptionGroup>` or `List<Slack.Option>`.

**important:** Constructing a `Slack.OptionDataResponse` with a combination of `Slack.Option` and `Slack.OptionGroup` isn’t supported. If both are present in the `Slack.OptionDataResponse`, the UI doesn't update.

### OptionDataResponse Constructors

The following are constructors for `OptionDataResponse`.

#### OptionDataResponse(options)

**Signature**

```java
public OptionDataResponse(List<Slack.Option> options)
```

**Parameters**

_options_

Type: List<Slack.Option>

#### OptionDataResponse(optionGroups)

**Signature**

```java
public OptionDataResponse(List<Slack.OptionGroup> optionGroups)
```

**Parameters**

_optionGroups_

Type: List<Slack.OptionGroup>

### OptionDataResponse Methods

The following are methods for `OptionDataResponse`.

#### getOptionGroups()

**Signature**

```java
public List<Slack.OptionGroup> getOptionGroups()
```

**Return Value**

Type: List<Slack.OptionGroup>

#### getOptions()

**Signature**

```java
public List<Slack.Option> getOptions()
```

**Return Value**

Type: List<Slack.Option>

---

## OptionGroup Class

Creates an option group for the [Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#select) or [External Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#external-select) component.

For the External Select component, construct your data using `List<Slack.OptionGroup>` and return it using `Slack.OptionDataResponse`.

Alternatively, specify the values or use an expression in the view definition for the [Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#select) or [External Select](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/elements.md#external-select) component.

### Usage

Use the `Slack.OptionGroup` class to build your option groups for the External Select component. See [Apex Data Providers for External Select Component](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/build/data-providers.md#apex-data-providers-for-external-select-component).

Alternatively, construct your data using `List<Slack.OptionGroup>` for the Select component.

```java
public class DataProviderOpportunityLookup {
    private static final String NO_OPPORTUNITY = 'Account has no Opportunity';
    private static final String MISSING_OR_INCORRECT_ACCOUNT_ID = 'Account Id is missing or is incorrect';

    public static List<Slack.OptionGroup> getOpportunitiesByStage(String accountId) {
      List<Slack.OptionGroup> opportunityOptionGroup;

      if (String.isNotBlank(accountId)) {
          List<Opportunity> opportunities = queryOpportunities(accountId);
          opportunityOptionGroup = new List<Slack.OptionGroup>();

          if (!opportunities.isEmpty()) {
              List<Slack.Option> newOptions = new List<Slack.Option>();
              List<Slack.Option> inProgressOptions = new List<Slack.Option>();
              List<Slack.Option> closedOptions = new List<Slack.Option>();

              for (Opportunity opp : opportunities) {
                  switch on opp.StageName {
                      when 'New' {
                          Slack.Option newOption = new Slack.Option(opp.Id, opp.Name);
                          newOptions.add(newOption);
                      }
                      when 'In Progress' {
                          Slack.Option inProgressOption = new Slack.Option(opp.Id, opp.Name);
                          inProgressOptions.add(inProgressOption);
                      }
                      when 'Closed' {
                          Slack.Option closedOption = new Slack.Option(opp.Id, opp.Name);
                          closedOptions.add(closedOption);
                      }
                  }
              }

              Slack.OptionGroup newOptionGroup = new Slack.OptionGroup('New Opportunities', newOptions);
              opportunityOptionGroup.add(newOptionGroup);
              Slack.OptionGroup inProgressOptionGroup = new Slack.OptionGroup('In Progress Opportunities', inProgressOptions);
              opportunityOptionGroup.add(inProgressOptionGroup);
              Slack.OptionGroup closedOptionGroup = new Slack.OptionGroup('Closed Opportunities', closedOptions);
              opportunityOptionGroup.add(closedOptionGroup);
          } else {
              opportunityOptionGroup.add(getEmptyOptionGroup());
          }
      } else {
          opportunityOptionGroup.add(getEmptyOptionGroup());
          System.debug(MISSING_OR_INCORRECT_ACCOUNT_ID);
      }

      return opportunityOptionGroup;
  }
}
```

See the [sample app](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/setup-install-app.md) for a full example.

### OptionGroup Constructor

`OptionGroup` has the following constructor.

#### OptionGroup(label, options)

Creates an instance of the `Slack.OptionGroup` class with the label and options.

**Signature**

```java
public OptionGroup(String label, List<Slack.Option> options)
```

**Parameters**

_label_

Type: String

The text label for the option group.

_options_

Type: List<Slack.Option>

A list of options to choose from.

### OptionGroup Methods

The following are methods for `OptionGroup`.

#### getLabel()

Gets the text label of the option group.

**Signature**

```java
public String getLabel()
```

**Return Type**

Type: String

#### getOptions()

Gets the list of options.

**Signature**

```java
public List<Slack.Option> getOptions()
```

**Return Type**

Type: List<Slack.Option>

## See Also

[Apex Data Providers for External Select Component](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/build/data-providers.md#apex-data-providers-for-external-select-component).
