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.
DataSourceInventory.cls
global classDataSourceInventoryimplementsSBLS.DataSourceService.Fetchable { global SBLS.DataSourceService.Resultexecute(SBLS.DataSourceService.Parameter params) {// Retrieve records from the ListList<SObject> records =params.gets();// Fetch DataSource values (e.g., inventory data) from an external APIMap<String,Integer> inventoryData =newMap<String,Integer>(); inventoryData.put('Product001',10);inventoryData.put('Product002',20);// Create the Result objectSBLS.DataSourceService.Result result =new SBLS.DataSourceService.Result();// Map DataSource values to List recordsfor (String productCode :inventoryData.keySet()) {SBLS.DataSourceService.Action action =new SBLS.DataSourceService.Action();action.setKeyValue(productCode); // Set the Key value for mappingaction.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 }}
1
Retrieve Records from the List
Use params.gets() to access the records retrieved by the List.
2
Prepare DataSource Values
Simulate fetching data from an external API to retrieve inventory information.
In the example, inventory data is mapped using ProductCode as the key.
// Create the Result objectSBLS.DataSourceService.Result result =new SBLS.DataSourceService.Result();// Map DataSource values to List recordsfor (String productCode :inventoryData.keySet()) {SBLS.DataSourceService.Action action =new SBLS.DataSourceService.Action();action.setKeyValue(productCode); // Set the Key value for mappingaction.putSourceToTargetField(inventoryData.get(productCode),// DataSource value: inventory'SBLS_Virtual1'// Virtual column API name );result.addAction(action); // Add Action to the Result}
4
Return the Result Object
Return the Result object containing the mapping information for integration with the List.
This class provides access to the Listβs records and fields selected during the builder configuration.
Example Code
global SBLS.DataSourceService.Resultexecute(SBLS.DataSourceService.Parameter params) {List<SObject> records =params.gets();...}
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.
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
DataSourceInventory.cls
...SBLS.DataSourceService.Result result =new SBLS.DataSourceService.Result();for (String productCode :inventoryData.keySet()) {// Create an Action object to store mapping informationSBLS.DataSourceService.Action action =new SBLS.DataSourceService.Action();action.setKeyValue(productCode); // Set the Key value for mappingaction.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;
Method
addAction(SBLS.DataSourceService.Action action)
Adds an Action object containing mapping details to the Result.
Parameter
Type
Value
action
An instance of the SBLS.DataSourceService.Action class that contains the mapping information between the List and the DataSource values.
The Action class stores mapping information between the DataSource and the List.
Example Code
DataSourceInventory.cls
SBLS.DataSourceService.Result result =new SBLS.DataSourceService.Result();// Process each product code and inventory information from the DataSourcefor (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 Itemaction.setKeyValue(productCode);// Map inventory information to the Inventory__c field in the List/Line Itemaction.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
Method
setKeyValue(Object keyValue)
Sets the Key value from the DataSource that corresponds to the Listβs Key.