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
    • Release Note
      • '25 Update
        • v 2.3
    • 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
    • Migration
      • JSON Export
      • JSON Import
  • πŸ“¦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
  • Properties
  • Creating an Apex class
  • SBLD.DataSourceServiceAction Class
  • SBLD.DataSourceService.Result Class
  • Example

Was this helpful?

Export as PDF
  1. SmallBuilder Lists
  2. Setup
  3. Data source setup

External data sources

Last updated 1 year ago

Was this helpful?

External data sources should be used when you want to retrieve data from an external server and present it alongside data from a standard or custom Salesforce object. Since the datasource is accessed using a user-defined Apex class, you can retrieve data more flexibly compared to an internal datasource.

For example, if you want to retrieve real-time inventory numbers from an external system and display them on-screen alongside your product information, you can write REST API code in an Apex Class to do this.

  • Describes the properties to be configured when using an external datasource.

  • Before you can use an external datasource, you must write an Apex class. Your class must implement the SBLD.DataSourceService.Fetchable interface provided in the package.


Properties

There are several properties to be configured when using an external datasource.

Field name or area
Description
Req.

Select the type of external connection.

There are two ways to connect to external datasources.

  • Apex - use an Apex class that implements the SBLD.DataSourceService.Fetchable interface.

  • Flow - use an automatically executing Flow.

βœ”οΈ

Enable

Enables the datasource. A disabled datasource will not be available when building custom lists.

Description

Provide a description of your datasource.

Key Field

Specifies which fields from the List object should be matched with fields from the datasource.

βœ”οΈ

Parameters

If your datasource needs to be passed values from fields in the List object, select those fields here.

Input Variable

Output Variable

βœ”οΈ

Creating an Apex class

Before you can use an external datasource, you must write an Apex class. Your class must implement the SBLD.DataSourceService.Fetchable interface provided in the package.

You must also implement the execute() method in your class.

DataSourceServiceMock.cls
global with sharing class DataSourceServiceMock implements SBLD.DataSourceService.Fetchable {
    /***
     * @description SBLD.DataSourceService.Fetchable execute() definition
     * @param param SBLD.DataSourceService.Parameter parameter type
     *              set by the datasource 
     * @return Map<Object, SObject>
     ****/
    global SBLD.DataSourceService.Result execute(SBLD.DataSourceService.Parameter param) {
        SBLD.DataSourceService.Result results = new SBLD.DataSourceService.Result();
        /**
         *  @method DataSourceService.Parameter gets()
         *  @param  String Parent, choose from Lookups (case insensitive)
         *  @return List<SObject>
         **/
        SObject parentRecord = null;
        List<SObject> lookupRecords = new List<SObject>();
        // Gets Parent-specific parameters.
        if(param.gets('parent')<>null && !param.gets('parent').isEmpty()) {
            parentRecord = param.gets('parent')[0];
        }
        // Gets Lookup-specific parameters.
        if(param.gets('lookup')<>null && !param.gets('lookup').isEmpty()) {
            listLookupParameters = param.gets('lookup');
        }
        /**
         * On success, sets the result to send back to SmallBuilder.
         **/
        for(SObject sobj : lookupRecords) {
            /**
             * Similarly to internal datasources, the Action maps a 
             * value from a datasource to a field in the List's underlying object.
             **/
            SBLD.DataSourceServiceAction action = new SBLD.DataSourceServiceAction();
            // 1. Set the value of the key from the External datasource
            action.setKeyValue(sobj.get('Id')); // Product Code
            // 2. Maps fields from the external datasource to fields in the List's underlying object.
            Map<String, Object> mapPopulatedField = sobj.getPopulatedFieldsAsMap();
            for(String fieldName : mapPopulatedField.keySet()) {
                action.putSourceToTargetField(mapPopulatedField.get(fieldName), fieldName);
            }
            // 3. Add an Action to DataSourceService.Result.
            results.addAction(action);
        }
        return results;
    }
}

You can get information from the Parent or Lookup objects through the gets() method in SBLD.DataSourceService.Parameter

global SBLD.DataSourceService.Result execute(SBLD.DataSourceService.Parameter param) {
    SObject parentRecord = null;
    List<SObject> lookupRecords = new List<SObject>();
    // Gets Parent-specific parameters.
    if(param.gets('parent')<>null && !param.gets('parent').isEmpty()) {
        parentRecord = param.gets('parent')[0];
    }
    // Gets Lookup-specific parameters.
    if(param.gets('lookup')<>null && !param.gets('lookup').isEmpty()) {
        listLookupParameters = param.gets('lookup');
    }
    ...
}

To pass the result to the Line-Item Configurator, we use the class below.

SBLD.DataSourceServiceAction Class

Specifies an Action for each line in the target (Lookup or Line-item). An Action is an operation that maps a DataSource value to a Lookup or Line-item field.

  • setKeyValue(Object keyValue) Sets the Key value to find the target record for the Lookup or Line-item.

  • putSourceToTargetField(Object sourceValue, String targetField) Assigns a data source value to a Lookup or Line-item field.

SBLD.DataSourceService.Result Class

Adds the mapped Action to the return value.

  • addAction(SBLD.DataSourceServiceAction action) Adds an Action to the SBLD.DataSourceService.Result instance.

...
SBLD.DataSourceService.Result result = new SBLD.DataSourceService.Result();
for(Object objResponse : listResponses) {
    Map<String, Object> mapResponse = (Map<String, Object>)objResponse;

    SBLD.DataSourceServiceAction action = new SBLD.DataSourceServiceAction();
    /**
     *  A value that matches the Key field in the DataSource
     *  External Server Key: itemCode,
     *  Lookup Key: ProductCode
     **/    action.setKeyValue(mapResponse.get('Id')); // Product Code
    // Populating a Lookup or Line-item field with a value from the External DataSoure
    action.putSourceToTargetField(mapResponse.get('inventory'), 'Inventory__c');
    // Add an Action to SBLD.DataSourceService.Result.
    result.addAction(action);
}
return result;

Example

Under construction! Contact us if you need further help.

Select the parameter variables to pass to the Flow. If no parameters are required, leave unchecked. πŸ’‘ The displayed options are those marked "Available for input" in the Flow.

Select the variables to receive the results from the Flow. πŸ’‘ The displayed options are those marked "Available for output" in the Flow.

πŸ“¦
Properties
Creating an Apex class
Example
Apex class for an external datasource
Flow for an external datasource