---
schema_version: "1"
id: 43a8e40c1a5de5fda9d7bbf7dcb18df6b2ce63f03bda390a3419439b3ead3af9
title: "Question with Dynamic Options: Example Apex Class"
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/service/264-0-0/bots_service_enhanced_question_dynamic_apex.md
canonical_url: https://help.salesforce.com/s/articleView?id=service.bots_service_enhanced_question_dynamic_apex.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 64d7efbb85d0b2aff2f02ac455106272b4d48e9b8d42a832b929e6b7b0af77f9
description: To use a question with dynamic options with your enhanced bot, create an Apex class to populate the options from the objects and fields you specify. The Apex class must return an ID list variable as output for use with the bot.
products:
  - Service Cloud
  - Service Intelligence
release: "264"
---
# Question with Dynamic Options: Example Apex Class

To use a question with dynamic options with your enhanced bot, create an Apex class to populate the options from the objects and fields you specify. The Apex class must return an ID list variable as output for use with the bot.

### Required Editions

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

This Apex class searches cases and filters by priority. It returns the three most recent high-priority cases and stores them in an ID list.

```
public class CaseSearch {
    @InvocableMethod(label = 'CaseSearch')
    public static List<List<Id>> getCases(){
        List<Id> result = new List<Id>();
        
        List<Case> cases = [SELECT Id FROM Case WHERE Priority='High' ORDER BY CreatedDate DESC LIMIT 3];

        for(Case c: cases) {
            result.add(c.Id);
        }
        
        return new List<List<Id>>{result};
    }
    
}
```

After you create an Apex class, in the bot, add an Apex action dialog step that references your Apex class and store the output in an ID list bot variable. In the associated Question (Dynamic) dialog step, reference the same ID list bot variable in the Record ID Options input parameter.