To use an Apex Class for the advanced DataSource setup, you must implement the SBLS.DataSourceService.Fetchable interface. This interface requires the implementation of the execute method, where you define the logic for processing data. The processed data, along with mapping information to the List, must be returned as an instance of the SBLS.DataSourceService.Result object.
This example demonstrates retrieving inventory quantities from an external API based on product codes and mapping them to a virtual column (SBLS_Virtual1) in the List.
Since the SBLS.DataSourceService.Fetchable interface is provided by the package, both the Apex Class and its methods must be declared as global to ensure external access.
This class provides access to the List’s records and fields selected during the builder configuration.
List<SObject> gets()
Returns the records retrieved from the List. If no parameters are added during the builder setup, this will return an empty value.
The Result class holds all mapping information between the DataSource and the List. Actions added to this object define how the data is integrated.
addAction(SBLS.DataSourceService.Action action)
Adds an Action object containing mapping details to the Result.
The Action class stores mapping information between the DataSource and the List.
setKeyValue(Object keyValue)
Sets the Key value from the DataSource that corresponds to the List’s Key.
putSourceToTargetField(Object sourceValue, String targetFieldApiName)
Maps the DataSource value to a field or virtual column in the List.
Simulate fetching data from an external API to retrieve inventory information.
In the example, inventory data is mapped using ProductCode as the key.
Create an instance of SBLS.DataSourceService.Action for each mapping.
Set the DataSource value to the corresponding List field or virtual column using putSourceToTargetField.
Add each action to the .
action
An instance of the SBLS.DataSourceService.Action class that contains the mapping information between the List and the DataSource values.
keyValue
Object
The Key value from the DataSource for mapping.
sourceValue
Object
The value retrieved from the DataSource.
targetFieldApiName
String
The API name of the List’s field or virtual column.
global class DataSourceInventory implements SBLS.DataSourceService.Fetchable {
global SBLS.DataSourceService.Result execute(SBLS.DataSourceService.Parameter params) {
// Retrieve records from the List
List<SObject> records = params.gets();
// Fetch DataSource values (e.g., inventory data) from an external API
Map<String, Integer> inventoryData = new Map<String, Integer>();
inventoryData.put('Product001', 10);
inventoryData.put('Product002', 20);
// Create the Result object
SBLS.DataSourceService.Result result = new SBLS.DataSourceService.Result();
// Map DataSource values to List records
for (String productCode : inventoryData.keySet()) {
SBLS.DataSourceService.Action action = new SBLS.DataSourceService.Action();
action.setKeyValue(productCode); // Set the Key value for mapping
action.putSourceToTargetField(
inventoryData.get(productCode), // DataSource value: inventory
'SBLS_Virtual1' // Virtual column API name
);
result.addAction(action); // Add Action to the Result
}
return result; // Return the final Result
}
}global SBLS.DataSourceService.Result execute(SBLS.DataSourceService.Parameter params) {
List<SObject> records = params.gets();
...
}...
SBLS.DataSourceService.Result result = new SBLS.DataSourceService.Result();
for (String productCode : inventoryData.keySet()) {
// Create an Action object to store mapping information
SBLS.DataSourceService.Action action = new SBLS.DataSourceService.Action();
action.setKeyValue(productCode); // Set the Key value for mapping
action.putSourceToTargetField(
inventoryData.get(productCode), // DataSource value: inventory quantity
'SBLS_Virtual1' // Target field: virtual column in the List
);
result.addAction(action); // Add Action to the Result
}
return result;SBLS.DataSourceService.Result result = new SBLS.DataSourceService.Result();
// Process each product code and inventory information from the DataSource
for (String productCode : inventoryData.keySet()) {
SBLS.DataSourceService.Action action = new SBLS.DataSourceService.Action();
// Set the product code as the Key value to map with the List/Line Item
action.setKeyValue(productCode);
// Map inventory information to the Inventory__c field in the List/Line Item
action.putSourceToTargetField(
inventoryData.get(productCode), // DataSource value: inventory
'SBLS_Virtual1' // Virtual column API name
);
result.addAction(action); // Add mapping information
}
return result; // Return the final result<String, Integer> inventoryData = new Map<String, Integer>();
inventoryData.put('Product001', 10);
inventoryData.put('Product002', 20);// Create the Result object
SBLS.DataSourceService.Result result = new SBLS.DataSourceService.Result();
// Map DataSource values to List records
for (String productCode : inventoryData.keySet()) {
SBLS.DataSourceService.Action action = new SBLS.DataSourceService.Action();
action.setKeyValue(productCode); // Set the Key value for mapping
action.putSourceToTargetField(
inventoryData.get(productCode), // DataSource value: inventory
'SBLS_Virtual1' // Virtual column API name
);
result.addAction(action); // Add Action to the Result
}The Advanced DataSource allows you to retrieve and display data from external servers alongside Salesforce data. By leveraging custom Apex Classes or Flows to fetch data, this feature offers greater flexibility and diverse data access compared to internal DataSources. It enables the integration of Salesforce data with external systems, providing a unified view in the List while supporting complex business logic and data transformations.
For instance, if you want to display real-time inventory data from an external server, you can write a REST API call in an Apex Class and specify it as the Advanced DataSource, enabling the data to be displayed in the List.
Click the ➕ button to add a DataSource.
Search for and select the target Apex Class.
Configure the following attributes:
Click the ➕ button to add a DataSource.
Search for and select the target Flow.
Configure the following attributes:
Select a field in the List’s object that shares a common value with the key set in the Apex Class.
✔️
4
Parameters
If the Apex Class requires field values from the List’s object, select and map those fields to be passed as parameters to the Apex Class.
✔️
Select variables to pass data to the Flow. This step is optional if no parameters are needed. 💡 The options displayed are the input variables (marked as “Available for input”) defined in the Flow.
✔️
4
Output Variable
Select variables to retrieve data from the Flow’s result. 💡 The options displayed are the output variables (marked as “Available for output”) defined in the Flow.
✔️
5
Key Field
Select a field in the List’s object that shares a common value with the output variable’s field in the Flow.
✔️
1
Active
Enable the DataSource. If not activated, it will not function during List configuration.
2
Description
Add a description for the DataSource.
3
1
Active
Enable the DataSource. If not activated, it will not function during List configuration.
2
Description
Add a description for the DataSource.
3

Key Field
Input Variable







