Options
All
  • Public
  • Public/Protected
  • All
Menu

DataSource SDK This SDK handles the connection with SalesForce and provide convenient ways to access Vlocity integration including DataRaptor, Integration Procedure, Apex REST API etc.

How to create a Datasource?

example

Getting an instance of the DataSource

// Obtain a singleton dataSourceService
const dataSourceService = DataSource.getInstance({
  salesforceUrl: "https://www.salesforce.com",
  sessionId: "123",
  create: false,
  userId: "test" //additional data
});
example

Creating a custom datasource at runtime

const newDataSource = {
 oracle: () => {
  return "I'm a Custom implementation";
 },
 siebel: () => {
   return "I'm a Custom implementation";
 }
};

dataSourceService.create(newDataSource, isNewInstance);

// Create function implementation looks like this
// uses prototype to add methods to dataSourceService

DataSource.mixin(DataSource, newDataSource, isNewInstance);
// call
dataSourceService
 .siebel()
 .execute(input)
 .then()
 .catch();
example

Using ApexRest

datasource
 .apexRest({
  method: "get",
  url:
    "/vlocity_cmt/v2/cpq/carts/80137000000WlMP/products?hierarchy=1&pagesize=10&fields=IsActive,Id,Name,UnitPrice,ProductCode,jraju_card__RecurringPrice__c&includeIneligible=true"
 })
  .execute()
  .then(resp => Logger.log("resp from thenable", resp))
  .catch(error => Logger.log("response from catch thenable", error));
example

Using Rest

const input1: IRestInput = { url: "/test.json" };
datasource
  .rest(input1)
  .execute()
  .then(response => {
    Logger.log("call ", response);
  })
  .catch(error => {
    Logger.log("fail", error);
  });
example

Using SOQL

datasource
  .soql({
   query: "SELECT Id, Name FROM Account LIMIT 10"
  } as ISoqlInput)
  .execute()
  .then(response => {
    Logger.log("soql call ", response.records);
  })
  .catch(error => {
   Logger.log("soql fail", error);
  });
example

SOSL call

datasource
  .sosl({
   query: "FIND {Un*} IN ALL FIELDS RETURNING Account LIMIT 10"
  } as ISoslInput)
  .execute()
  .then(response => {
    Logger.log("sosl call " + response.searchRecords);
  })
 .catch(error => {
    Logger.log("sosl fail" + error);
 });

Hierarchy

Index

Constructors

constructor

  • Create a new DataSource.

    Parameters

    • config: any

    Returns DataSource

Properties

config

Config for this SDK.

connection

connection: any

Static Private instance

instance: DataSource

Private singleton instance of this SDK. There should always be only 1 instance.

Accessors

namespace

  • get namespace(): string
  • set namespace(customNamespace: string): void
  • getter method for namespace. Provides the salesforce org namespace

    Returns string

  • setter method for namespace. Set custom namespace

    Parameters

    • customNamespace: string

    Returns void

Methods

apexRemote

apexRest

dataRaptor

  • Create a new dataRaptor wrapper

    Parameters

    Returns DataRaptor

dual

  • Create a dual data source that will automatically switch between Apex Rest or Apex Remote (if available).

    Parameters

    Returns IDataSource

    a instance of DualDataSource.

integrationProcedure

rest

  • Create a new Rest wrapper

    Parameters

    • url: string
    • Optional options: RequestInit

    Returns RestDataSource

soql

  • Create a new Soql wrapper

    Parameters

    Returns SoqlDataSource

sosl

  • Create a new Sosl wrapper

    Parameters

    Returns SoslDataSource

version

  • version(): string
  • Returns the version number of SDK.

    Returns string

    Returns SDK version number as string

Static extend

  • extend(extendObj: object): void
  • Adds all the enumerable string keyed function properties of a source object to the sdk prototype. .extend should only be used to add new methods and it won't override the existing methods.

    Note: If the property already exists, it will be not be added.

    Custom functions which are being extended should have proper namespaces to avoid issues during upgrades. When Vlocity releases new changes it won't impact if unique namespaces are used.

    Example: myCompanyOrFeatureMethodName

    example

    How to extend an sdk?

    VlocitySDK.datasource.extend({ myCompanySayHello(){
         console.log("Hello World");
      }, sayTime() {
         console.log(new Date().myCompanyGetTime());
      }});
    
    const dataSource = VlocitySDK.datasource.getInstance({'create':true});
    console.log(daSource.myCompanySayHello())

    Parameters

    • extendObj: object

      The object of functions

    Returns void

Static getInstance

  • Get an instance of DataSource if it exists. Otherwise, create a new one with the given config.

    Parameters

    Returns DataSource

    DataSource instance.

Static override

  • override(overrideObj: object): void
  • Adds all the enumerable string keyed function properties of a source object to the sdk prototype.

    .override method should only be used to override the existing methods and should only be used in rare cases. Overriding the existing or default methods may cause unintended consequences and may also impact during upgrades.

    Please be cautious while using this

    example

    How to override methods in an sdk?

    VlocitySDK.datasource.override({ soql(){
         console.log("This code overrides the default soql function");
         // code goes here...
      }, sosl() {
         console.log("This code overrides the default soql function");
         // code goes here...
      }});
    
    const dataSource = VlocitySDK.datasource.getInstance({'create':true});
    console.log(dataSource.soql()); // prints "This code overrides the default soql function"

    Parameters

    • overrideObj: object

      The object of functions

    Returns void

Generated using TypeDoc