Skip to main content

salesforce@4.6.2

Functions

bulk(sObject, operation, options, records)
bulkQuery(qs, options, callback)
cleanupState(state)
create(sObject, attrs)
createIf(logical, sObject, attrs)
describe(sObject)
describeAll()
destroy(sObject, attrs, options)
execute(operations)
query(qs, options, callback)
reference(position)
relationship(relationshipName, externalId, dataSource)
request(url, options, callback)
retrieve(sObject, id, callback)
steps()
toUTF8(input)
update(sObject, attrs)
upsert(sObject, externalId, attrs)
upsertIf(logical, sObject, externalId, attrs)

The following functions are exported from the common adaptor:

alterState()
arrayToString()
beta()
chunk()
combine()
dataPath()
dataValue()
dateFns()
each()
expandReferences()
field()
fields()
fn()
http()
humanProper()
index()
join()
jsonValue()
lastReferenceValue()
map()
merge()
referencePath()
scrubEmojis()
source()
sourceValue()
toArray()

bulk

bulk(sObject, operation, options, records) ⇒ Operation

Create and execute a bulk job.

ParamTypeDescription
sObjectStringAPI name of the sObject.
operationStringThe bulk operation to be performed
optionsObjectOptions passed to the bulk api.
recordsfunctionan array of records, or a function which returns an array.

Example

bulk('Patient__c', 'insert', { failOnError: true, pollInterval: 3000, pollTimeout: 240000 }, state => {
return state.data.someArray.map(x => {
return { 'Age__c': x.age, 'Name': x.name }
})
});

bulkQuery

bulkQuery(qs, options, callback) ⇒ Operation

Execute an SOQL Bulk Query. This function uses bulk query to efficiently query large data sets and reduce the number of API requests. Note that in an event of a query error, error logs will be printed but the operation will not throw the error.

ParamTypeDescription
qsStringA query string.
optionsObjectOptions passed to the bulk api.
[options.pollTimeout]integerPolling timeout in milliseconds.
[options.pollInterval]integerPolling interval in milliseconds.
callbackfunctionA callback to execute once the record is retrieved

Example (The results will be available on `state.data`)

bulkQuery(state=> `SELECT Id FROM Patient__c WHERE Health_ID__c = '${state.data.field1}'`);

Example

bulkQuery(
(state) =>
`SELECT Id FROM Patient__c WHERE Health_ID__c = '${state.data.field1}'`,
{ pollTimeout: 10000, pollInterval: 6000 }
);

cleanupState

cleanupState(state) ⇒ State

Removes unserializable keys from the state.

ParamType
stateState

Example

cleanupState(state)

create

create(sObject, attrs) ⇒ Operation

Create a new object.

ParamTypeDescription
sObjectStringAPI name of the sObject.
attrsObjectField attributes for the new object.

Example

create('obj_name', {
attr1: "foo",
attr2: "bar"
})

createIf

createIf(logical, sObject, attrs) ⇒ Operation

Create a new object if conditions are met.

ParamTypeDescription
logicalbooleana logical statement that will be evaluated.
sObjectStringAPI name of the sObject.
attrsObjectField attributes for the new object.

Example

createIf(true, 'obj_name', {
attr1: "foo",
attr2: "bar"
})

describe

describe(sObject) ⇒ Operation

Outputs basic information about an sObject to STDOUT.

ParamTypeDescription
sObjectStringAPI name of the sObject.

Example

describe('obj_name')

describeAll

describeAll() ⇒ Operation

Outputs basic information about available sObjects.

Example

describeAll()

destroy

destroy(sObject, attrs, options) ⇒ Operation

Delete records of an object.

ParamTypeDescription
sObjectStringAPI name of the sObject.
attrsObjectArray of IDs of records to delete.
optionsObjectOptions for the destroy delete operation.

Example

destroy('obj_name', [
'0060n00000JQWHYAA5',
'0090n00000JQEWHYAA5
], { failOnError: true })

execute

execute(operations) ⇒ State

Executes an operation.

ParamTypeDescription
operationsOperationOperations

query

query(qs, options, callback) ⇒ Operation

Execute an SOQL query. Note that in an event of a query error, error logs will be printed but the operation will not throw the error.

ParamTypeDescription
qsStringA query string.
optionsObjectOptions passed to the bulk api.
[options.autoFetch]booleanFetch next records if available.
callbackfunctionA callback to execute once the record is retrieved

Example

query(state=> `SELECT Id FROM Patient__c WHERE Health_ID__c = '${state.data.field1}'`);

Example (Query more records if next records are available)

query(state=> `SELECT Id FROM Patient__c WHERE Health_ID__c = '${state.data.field1}'`, { autoFetch: true });

reference

reference(position) ⇒ State

Get a reference ID by an index.

ParamTypeDescription
positionnumberPosition for references array.

Example

reference(0)

relationship

relationship(relationshipName, externalId, dataSource) ⇒ object

Adds a lookup relation or 'dome insert' to a record.

ParamTypeDescription
relationshipNamestring__r relationship field on the record.
externalIdstringSalesforce ExternalID field.
dataSourcestringresolvable source.

Example

Data Sourced Value:
relationship("relationship_name__r", "externalID on related object", dataSource("path"))
Fixed Value:
relationship("relationship_name__r", "externalID on related object", "hello world")

request

request(url, options, callback) ⇒ Operation

Send a HTTP request using connected session information.

ParamTypeDescription
urlStringRelative or absolute URL to request from
optionsObjectRequest options
[options.method]StringHTTP method to use. Defaults to GET
[options.headers]ObjectObject of request headers
[options.json]ObjectA JSON Object request body
[options.body]StringHTTP body (in POST/PUT/PATCH methods)
callbackfunctionA callback to execute once the request is complete

Example

request('/actions/custom/flow/POC_OpenFN_Test_Flow', {
method: 'POST',
json: { inputs: [{}] },
});

retrieve

retrieve(sObject, id, callback) ⇒ Operation

Retrieves a Salesforce sObject(s).

ParamTypeDescription
sObjectStringThe sObject to retrieve
idStringThe id of the record
callbackfunctionA callback to execute once the record is retrieved

Example

retrieve('ContentVersion', '0684K0000020Au7QAE/VersionData');

steps

steps() ⇒ Array

Flattens an array of operations.

Example

steps(
createIf(params),
update(params)
)

toUTF8

toUTF8(input) ⇒ String

Transliterates unicode characters to their best ASCII representation

Returns: String - - ASCII representation of input string

ParamTypeDescription
inputstringA string with unicode characters

Example

fn((state) => {
const s = toUTF8("άνθρωποι");
console.log(s); // anthropoi
return state;
});

update

update(sObject, attrs) ⇒ Operation

Update an object.

ParamTypeDescription
sObjectStringAPI name of the sObject.
attrsObjectField attributes for the new object.

Example

update('obj_name', {
attr1: "foo",
attr2: "bar"
})

upsert

upsert(sObject, externalId, attrs) ⇒ Operation

Upsert an object.

ParamTypeDescription
sObjectStringAPI name of the sObject.
externalIdStringID.
attrsObjectField attributes for the new object.

Example

upsert('obj_name', 'ext_id', {
attr1: "foo",
attr2: "bar"
})

upsertIf

upsertIf(logical, sObject, externalId, attrs) ⇒ Operation

Upsert if conditions are met.

ParamTypeDescription
logicalbooleana logical statement that will be evaluated.
sObjectStringAPI name of the sObject.
externalIdStringID.
attrsObjectField attributes for the new object.

Example

upsertIf(true, 'obj_name', 'ext_id', {
attr1: "foo",
attr2: "bar"
})