The Trailblazer Community in Slack is now in Open Beta—join and connect in real time. [Join us in Slack]
Use these Apex classes to implement a Select component or a data provider specified by the datasource key on an External Select component.
The sample app has several examples that use the Select and External Select components.
Tip
Creates an option for the Select or 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 or External Select component.
Construct List<Slack.Option> to build a list of values for the Select component.
1public class DataProviderOpportunityLookup {
2 private static final String NO_OPPORTUNITY = 'Account has no Opportunity';
3 private static final String MISSING_OR_INCORRECT_ACCOUNT_ID = 'Account Id is missing or is incorrect';
4
5 /* Use List<Slack.Option> to retrieve all opportunities by accountId.
6 Return result in the format List<String, String> to the view. */
7 public static List<Slack.Option> getOpportunitiesByAccount(String accountId) {
8 List<Slack.Option> oppOptions;
9
10 if (String.isNotBlank(accountId)) {
11 List<Opportunity> opps = queryOpportunities(accountId);
12 oppOptions = new List<Slack.Option>();
13
14 if (!opps.isEmpty()) {
15 for (Opportunity opp : opps) {
16 Slack.Option oppOption = new Slack.Option(opp.Name, opp.Id);
17 oppOptions.add(oppOption);
18 }
19 } else {
20 oppOptions.add(new Slack.Option(NO_OPPORTUNITY, NO_OPPORTUNITY));
21 }
22 } else {
23 oppOptions = new List<Slack.Option>{ new Slack.Option(MISSING_OR_INCORRECT_ACCOUNT_ID, MISSING_OR_INCORRECT_ACCOUNT_ID) };
24 System.debug(MISSING_OR_INCORRECT_ACCOUNT_ID);
25 }
26
27 return oppOptions;
28 }
29}See the sample app 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.
1public class DataProviderAccountLookup {
2 public static Slack.OptionDataResponse getAccountsByName(String value) {
3 List<Account> accounts;
4 if (String.isNotBlank(value)) {
5 String name = '%' + value + '%';
6 accounts = [SELECT Id, Name FROM Account WHERE Name LIKE :name WITH SECURITY_ENFORCED LIMIT 10];
7 }
8
9 List<Slack.Option> accountOptions = new List<Slack.Option>();
10 if (accounts != null) {
11 for (Account account : accounts) {
12 Slack.Option option = new Slack.Option(account.Name, account.Id);
13 accountOptions.add(option);
14 }
15 }
16 return new Slack.OptionDataResponse(accountOptions);
17 }
18}Option has the following constructor.
Creates an instance of the Slack.Option class with the text and value.
Signature
1public Option(String text, String value)Parameters
text
Type: String
The text to display on the component.
value
Type: String
The value of the option.
The following are methods for Option.
Gets the display text for the component.
Signature
1public String getText()Return Type
Type: String
Gets the value of the option.
Signature
1public String getValue()Return Type
Type: String
The data to return for the External Select component using a List<Slack.Option> or List<Slack.OptionGroup>.
Construct Slack.OptionDataResponse with List<Slack.OptionGroup> or List<Slack.Option>.
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.
Important
The following are constructors for OptionDataResponse.
Signature
1public OptionDataResponse(List<Slack.Option> options)Parameters
options
Type: List<Slack.Option>
Signature
1public OptionDataResponse(List<Slack.OptionGroup> optionGroups)Parameters
optionGroups
Type: List<Slack.OptionGroup>
The following are methods for OptionDataResponse.
Signature
1public List<Slack.OptionGroup> getOptionGroups()Return Value
Type: List<Slack.OptionGroup>
Signature
1public List<Slack.Option> getOptions()Return Value
Type: List<Slack.Option>
Creates an option group for the Select or 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 or External Select component.
Use the Slack.OptionGroup class to build your option groups for the External Select component. See Apex Data Providers for External Select Component.
Alternatively, construct your data using List<Slack.OptionGroup> for the Select component.
1public class DataProviderOpportunityLookup {
2 private static final String NO_OPPORTUNITY = 'Account has no Opportunity';
3 private static final String MISSING_OR_INCORRECT_ACCOUNT_ID = 'Account Id is missing or is incorrect';
4
5 public static List<Slack.OptionGroup> getOpportunitiesByStage(String accountId) {
6 List<Slack.OptionGroup> opportunityOptionGroup;
7
8 if (String.isNotBlank(accountId)) {
9 List<Opportunity> opportunities = queryOpportunities(accountId);
10 opportunityOptionGroup = new List<Slack.OptionGroup>();
11
12 if (!opportunities.isEmpty()) {
13 List<Slack.Option> newOptions = new List<Slack.Option>();
14 List<Slack.Option> inProgressOptions = new List<Slack.Option>();
15 List<Slack.Option> closedOptions = new List<Slack.Option>();
16
17 for (Opportunity opp : opportunities) {
18 switch on opp.StageName {
19 when 'New' {
20 Slack.Option newOption = new Slack.Option(opp.Id, opp.Name);
21 newOptions.add(newOption);
22 }
23 when 'In Progress' {
24 Slack.Option inProgressOption = new Slack.Option(opp.Id, opp.Name);
25 inProgressOptions.add(inProgressOption);
26 }
27 when 'Closed' {
28 Slack.Option closedOption = new Slack.Option(opp.Id, opp.Name);
29 closedOptions.add(closedOption);
30 }
31 }
32 }
33
34 Slack.OptionGroup newOptionGroup = new Slack.OptionGroup('New Opportunities', newOptions);
35 opportunityOptionGroup.add(newOptionGroup);
36 Slack.OptionGroup inProgressOptionGroup = new Slack.OptionGroup('In Progress Opportunities', inProgressOptions);
37 opportunityOptionGroup.add(inProgressOptionGroup);
38 Slack.OptionGroup closedOptionGroup = new Slack.OptionGroup('Closed Opportunities', closedOptions);
39 opportunityOptionGroup.add(closedOptionGroup);
40 } else {
41 opportunityOptionGroup.add(getEmptyOptionGroup());
42 }
43 } else {
44 opportunityOptionGroup.add(getEmptyOptionGroup());
45 System.debug(MISSING_OR_INCORRECT_ACCOUNT_ID);
46 }
47
48 return opportunityOptionGroup;
49 }
50}See the sample app for a full example.
OptionGroup has the following constructor.
Creates an instance of the Slack.OptionGroup class with the label and options.
Signature
1public 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.
The following are methods for OptionGroup.
Gets the text label of the option group.
Signature
1public String getLabel()Return Type
Type: String
Gets the list of options.
Signature
1public List<Slack.Option> getOptions()Return Type
Type: List<Slack.Option>
Apex Data Providers for External Select Component.
Beta Feature