Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Callable Interface
Namespace
Usage
To implement the Callable interface, you need to write only one method: call(String action, Map<String, Object> args).
In code that utilizes or tests an implementation of Callable, cast an instance of your type to Callable.
This interface is not intended to replace defining more specific interfaces. Rather, the Callable interface allows integrations in which code from different classes or packages can use common base types.
Callable Methods
The following are methods for Callable.
Callable Example Implementation
1public class Extension implements Callable {
2
3 // Actual method
4 String concatStrings(String stringValue) {
5 return stringValue + stringValue;
6 }
7
8 // Actual method
9 Decimal multiplyNumbers(Decimal decimalValue) {
10 return decimalValue * decimalValue;
11 }
12
13 // Dispatch actual methods
14 public Object call(String action, Map<String, Object> args) {
15 switch on action {
16 when 'concatStrings' {
17 return this.concatStrings((String)args.get('stringValue'));
18 }
19 when 'multiplyNumbers' {
20 return this.multiplyNumbers((Decimal)args.get('decimalValue'));
21 }
22 when else {
23 throw new ExtensionMalformedCallException('Method not implemented');
24 }
25 }
26 }
27
28 public class ExtensionMalformedCallException extends Exception {}
29}1@IsTest
2private with sharing class ExtensionCaller {
3
4 @IsTest
5 private static void givenConfiguredExtensionWhenCalledThenValidResult() {
6
7 // Given
8 String extensionClass = 'Extension'; // Typically set via configuration
9 Decimal decimalTestValue = 10;
10
11 // When
12 Callable extension =
13 (Callable) Type.forName(extensionClass).newInstance();
14 Decimal result = (Decimal)
15 extension.call('multiplyNumbers', new Map<String, Object> {
16 'decimalValue' => decimalTestValue
17 });
18
19 // Then
20 System.assertEquals(100, result);
21 }
22}