Writing an Apex Class
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.
🔸 Example Code
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.
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
}
}Generate the Result Object
Create an instance of
SBLS.DataSourceService.Actionfor each mapping.Set the DataSource value to the corresponding List field or virtual column using putSourceToTargetField.
Add each action to the
SBLS.DataSourceService.Result.
🔸 SBLS.DataSourceService.Parameter
This class provides access to the List’s records and fields selected during the builder configuration.
Example Code
Method
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.
🔸 SBLS.DataSourceService.Result
The Result class holds all mapping information between the DataSource and the List. Actions added to this object define how the data is integrated.
Example Code
Method
addAction(SBLS.DataSourceService.Action action)
Adds an Action object containing mapping details to the Result.
action
An instance of the SBLS.DataSourceService.Action class that contains the mapping information between the List and the DataSource values.
🔸 SBLS.DataSourceService.Action
The Action class stores mapping information between the DataSource and the List.
Example Code
Method
setKeyValue(Object keyValue)
Sets the Key value from the DataSource that corresponds to the List’s Key.
keyValue
Object
The Key value from the DataSource for mapping.
putSourceToTargetField(Object sourceValue, String targetFieldApiName)
Maps the DataSource value to a field or virtual column in the List.
sourceValue
Object
The value retrieved from the DataSource.
targetFieldApiName
String
The API name of the List’s field or virtual column.
Last updated
Was this helpful?