All pages
Powered by GitBook
1 of 2

Loading...

Loading...

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.

1

Retrieve Records from the List

Use params.gets() to access the records retrieved by the List.

2


🔸 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.

Parameter
Type
Value

🔸 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.

Parameter
Type
Value

putSourceToTargetField(Object sourceValue, String targetFieldApiName)

Maps the DataSource value to a field or virtual column in the List.

Parameter
Type
Value
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.

3

Generate the Result Object

  • 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 .

4

Return the Result Object

Return the Result object containing the mapping information for integration with the List.

action

SBLS.DataSourceService.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.

DataSourceInventory.cls
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();
    ...
}
DataSourceInventory.cls
...
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;
DataSourceInventory.cls
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);
SBLS.DataSourceService.Result
// 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
}

Advanced DataSource

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.

Multiple DataSources can be configured and used simultaneously.

What is Key?

A Key is a common field used to merge data from the DataSource into the List. It ensures proper integration by linking data from the external DataSource with the List records.

Apex Class Advanced DataSource Setup

To configure an Advanced DataSource with an Apex Class, you must first create the Apex Class. Implement the SBLD.DataSourceService.Fetchable interface provided by the SmallBuilder Lists package in the Apex Class you want to use.

Learn more about writing Apex Classes >


🔸 Steps to Configure Apex Class Advanced DataSource

  1. Click the ➕ button to add a DataSource.

  2. Search for and select the target Apex Class.

  3. Configure the following attributes:

No.
Name
Description
Required

🔸 Steps to Configure Flow Advanced DataSource

  1. Click the ➕ button to add a DataSource.

  2. Search for and select the target Flow.

  3. Configure the following attributes:

No.
Name
Description
Required

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

Advanced DataSource Setup
Search Apex Class
Advanced DataSource for Apex Class Setup
Advanced DataSource Setup
Search Flow
Advanced DataSource for Flow Setup

Key Field

Input Variable