---
schema_version: "1"
id: 291d74959f3bb1897e29975ff82d94a2df696f483e606e22f05baf1f39482c88
title: "Example: Apex Class for Time Selector Messaging Components"
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/service/264-0-0/messaging_components_apex_class.md
canonical_url: https://help.salesforce.com/s/articleView?id=service.messaging_components_apex_class.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: f4befe90ff4e44a54233abc3edf4e3c4b7f5908b98eede0a52b40f00e0826cc0
description: Time selector messaging components send customers a prompt and a list of available time slots for them to choose from. To generate the list of time slots each time the component is sent, create an Apex class. The Apex class determines the time slot start time, duration, and time zone.
products:
  - Service Cloud
  - Digital Engagement
release: "264"
---
# Example: Apex Class for Time Selector Messaging Components

Time selector messaging components send customers a prompt and a list of available time slots for them to choose from. To generate the list of time slots each time the component is sent, create an Apex class. The Apex class determines the time slot start time, duration, and time zone.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <tbody>
          <tr class="">
            <td class="slds-cell-wrap" colspan="2" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=service.messaging_editions.htm&amp;type=5&amp;language=en_US" target="_blank">View supported editions.</a></td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <a name="messaging_components_apex_class__d1032e2806"><!-- --></a><span style="vertical-align:text-bottom;display:inline-block;"><img style="margin-bottom:0;" id="messaging_components_apex_class__d1032e2806" src="https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/resources-global/_corporate/images/checkmark.png" alt="Checkmark"></span>
              <strong>This article applies to:</strong>
            </td>

            <td class="slds-cell-wrap" style="vertical-align:top;">Enhanced In-App Chat, Enhanced Web Chat v1, Enhanced WhatsApp, Enhanced Facebook
              Messenger, and Enhanced Apple Messages for Business, and Bring Your Own
              Channel</td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <span style="vertical-align:text-bottom;display:inline-block;"><img style="margin-bottom:0;" src="https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/resources-global/_corporate/images/crossmark.png" alt="X icon"></span>
              <strong>This article doesn’t apply to:</strong>
            </td>

            <td class="slds-cell-wrap" style="vertical-align:top;">Enhanced Web Chat v2, Standard and Enhanced SMS, and Enhanced LINE</td>

          </tr>
        </tbody>
      </table>

This Apex class provides example time slots at several intervals, each set by a pair of Datetime statements.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/images/icon_example.png)

Example

```java
public with sharing class MessagingTimeSlotOptions {
    
    @InvocableMethod
    public static List<List<RichMessaging.TimeSlotOption>> getTimeSlotOptions(){
        List<List<RichMessaging.TimeSlotOption>> result = new List<List<RichMessaging.TimeSlotOption>>();
        List<RichMessaging.TimeSlotOption> options = new List<RichMessaging.TimeSlotOption>{
            new RichMessaging.TimeSlotOption(
                Datetime.now().addHours(1),
                Datetime.now().addHours(2)),
            new RichMessaging.TimeSlotOption(
                Datetime.now().addHours(3),
                Datetime.now().addHours(4)),
            new RichMessaging.TimeSlotOption(
                Datetime.now().addHours(25),
                Datetime.now().addHours(26)),
            new RichMessaging.TimeSlotOption(
                Datetime.now().addHours(27),
                Datetime.now().addHours(28))
        };

        result.add(options);
        return result;
    }
}
```

#### See Also

- [Apex Code Overview](https://help.salesforce.com/s/articleView?id=platform.code_about.htm&type=5&language=en_US)