SmallBuilder Help
AppExchangeContact Us
🇺🇸 English
🇺🇸 English
  • SmallBuilder Help
  • Getting started with SmallBuilder
    • License and Permission Set Assignment
    • Organization Currency Setup
    • Connected App Configuration
  • 📦SmallBuilder Line Items
    • Release Notes
      • '25 Update
        • v 1.38
        • v 1.37
    • SmallBuilder Line Items Overview
    • Getting Started
      • Assigning Licenses and Permissions
      • Organization Currency Setup
      • Connected App Setup
    • Builder
      • Getting Stared with the Builder
      • Default Setting
        • Responsive Screen Configuration for Devices
        • Adjusting Editor Screen Ratio
        • Modifying Editor Labels
        • Lookup Selector Settings
          • Search All on Load
          • Expand Filters by Default
          • Allow Select Duplicate Item
          • Caching to Improve Performance
          • Records Per Page
        • Line Item Editor Settings
          • Show Summary
          • Freeze First Column
      • Builder Setup Steps
        • Relate Objects
          • Parent Object
          • Line Item Object
            • Set Object and Parent Reference Field
            • Set Filters and Sorting for Saved Line Items
            • Control Line Item Deletion
            • Set Auto-Numbering
          • Lookup Object
            • Select Lookup Reference Field
            • Set Keyword Search
            • Block Lookup Selector
            • Set Filters and Sorting for Lookup Records
        • Setup Lookup Selector
          • Add Columns
          • Reorder Columns
          • Change Column Labels
          • Set Column Width
          • Change Text Alignment
          • Add Virtual Columns for DataSource
        • Setup Line Item Editor
          • Add Columns
          • Reorder Columns
          • Change Column Labels
          • Set Default Value
          • Source Field: Assigning Default Values from Parent or Lookup Fields
          • Set Column Width
          • Change Text Alignment
          • Set Field Input to Read-Only
          • Set Field Input as Required
          • Display Totals
          • Hidden Setting for Line Item Editor Columns
          • Exclude Certain Fields from Saving
        • Preview
        • Activate
        • Create Button and Add to Page Layout
      • DataSource
        • Basic DataSource: Retrieve Related Object Data
        • Advanced: Retrieve Data Using Apex Classes
      • Cloning the Builder
      • Resetting a Builder
      • Insert Filters Using the Query Wizard
      • Inserting Custom Labels into Editor Labels
    • Product Option
      • Product Option Setup Steps
        • Activate Product Options
        • Configure Product Options
          • Default Setting
          • Line Item Setting
        • Configure Product Option Data
      • Display and Storage of Line Item Option Values
    • Use Cases
      • Utilizing the Editor’s Aura Component
    • FAQ
  • 📦SmallBuilder Lists
    • SmallBuilder Lists Introduction
    • Getting Started with SmallBuilder Lists
      • Assigning Licenses and Permissions
      • Organization Currency Setup
      • Connected App Setup
    • Getting Started with Builder
    • Builder Setup Steps
      • Default Setup
        • Title
        • Legend
        • Allow Export
        • Allow Import
        • Show Icon
      • Datatable Setup
        • QUERY
        • Multi Selectable
        • Show Summary
        • Add and Edit Columns
          • Column Editing by Type
        • Add Virtual Column
        • Add Row Action
      • Data Import Setup
      • Action Setup
        • Add Action
      • Filter Setup
        • Add and Configure Filters
          • Filter Editing by Type
      • Compact Configurator Setup
        • Add and Configure Columns
          • Editing by Column Type
      • Mobile Setup
      • DataSource Setup
        • Basic DataSource
          • Add and Configure Actions
        • Advanced DataSource
          • Writing an Apex Class
      • List Deployment and Management
        • Creating a List Configurator Manually
  • 📦SmallBuilder Documents
    • SmallBuilder Documents Introduction
    • Quick start
    • Components
    • Data Merge
      • Data Merge - Text
      • Data Merge - Related List
    • Document Job
    • Basic usage examples
      • How to pin a logo image to the top of the page
      • How to leave a gap between the components
      • How to add separators between the components
    • Advanced usage examples
      • Creating an invoice template
      • Automatically email invoices with a trigger
    • FAQ
    • 🌟Release Note
      • '24 Update
        • v. 1.50 ~
  • 📦SmallBuilder Schedules
    • SmallBuilder Schedules Introduction
    • Quick start: creating a new Schedule configurator
    • Detailed setup guide
      • Basic settings (Side Panel)
      • Linked objects setup
      • Control Field setup
      • Schedule Object setup
      • Saving and activating
    • FAQ
  • ❓SmallBuilder Troubleshooting
    • SmallBuilder Troubleshooting Help
      • Add Button Warning (If the button is not added to the page)
      • Add Tab Warning (Tabs are created and added to the app, but not visible)
Powered by GitBook
On this page
  • Example Code
  • SBLS.DataSourceService.Parameter
  • SBLS.DataSourceService.Result
  • SBLS.DataSourceService.Action

Was this helpful?

Export as PDF
  1. SmallBuilder Lists
  2. Builder Setup Steps
  3. DataSource Setup
  4. Advanced DataSource

Writing an Apex Class

PreviousAdvanced DataSourceNextList Deployment and Management

Last updated 4 months ago

Was this helpful?

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

<String, Integer> inventoryData = new Map<String, Integer>(); 
inventoryData.put('Product001', 10);
inventoryData.put('Product002', 20);
3

Generate the Result Object

  • Set the DataSource value to the corresponding List field or virtual column using putSourceToTargetField.

// 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
}
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.Result execute(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 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;

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

Method

setKeyValue(Object keyValue)

Sets the Key value from the DataSource that corresponds to the List’s Key.

Parameter
Type
Value

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.

Parameter
Type
Value

sourceValue

Object

The value retrieved from the DataSource.

targetFieldApiName

String

The API name of the List’s field or virtual column.

Create an instance of for each mapping.

Add each action to the .

SBLS.DataSourceService.Parameter

SBLS.DataSourceService.Result

SBLS.DataSourceService.Action

📦
🔸
🔸
🔸
🔸
SBLS.DataSourceService.Action
SBLS.DataSourceService.Result
SBLS.DataSourceService.Action