salesforce@4.6.5
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.
Param | Type | Description |
---|---|---|
sObject | String | API name of the sObject. |
operation | String | The bulk operation to be performed |
options | Object | Options passed to the bulk api. |
records | function | an 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.
bulkQuery()
uses Bulk API v.2.0 which is available in API version 41.0 and later.
This API is subject to rate limits.
Param | Type | Default | Description |
---|---|---|---|
qs | String | A query string. | |
options | Object | Options passed to the bulk api. | |
[options.pollTimeout] | integer | 90000 | Polling timeout in milliseconds. |
[options.pollInterval] | integer | 3000 | Polling interval in milliseconds. |
callback | function | A 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.
Param | Type |
---|---|
state | State |
Example
cleanupState(state)
create
create(sObject, attrs) ⇒ Operation
Create a new object.
Param | Type | Description |
---|---|---|
sObject | String | API name of the sObject. |
attrs | Object | Field 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.
Param | Type | Description |
---|---|---|
logical | boolean | a logical statement that will be evaluated. |
sObject | String | API name of the sObject. |
attrs | Object | Field 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
.
Param | Type | Description |
---|---|---|
sObject | String | API 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.
Param | Type | Description |
---|---|---|
sObject | String | API name of the sObject. |
attrs | Object | Array of IDs of records to delete. |
options | Object | Options for the destroy delete operation. |
Example
destroy('obj_name', [
'0060n00000JQWHYAA5',
'0090n00000JQEWHYAA5
], { failOnError: true })
execute
execute(operations) ⇒ State
Executes an operation.
Param | Type | Description |
---|---|---|
operations | Operation | Operations |
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.
The Salesforce query API is subject to rate limits, See for more details.
Param | Type | Default | Description |
---|---|---|---|
qs | String | A query string. Must be less than 4000 characters in WHERE clause | |
options | Object | Options passed to the bulk api. | |
[options.autoFetch] | boolean | false | Fetch next records if available. |
callback | function | A 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.
Param | Type | Description |
---|---|---|
position | number | Position for references array. |
Example
reference(0)
relationship
relationship(relationshipName, externalId, dataSource) ⇒ object
Adds a lookup relation or 'dome insert' to a record.
Param | Type | Description |
---|---|---|
relationshipName | string | __r relationship field on the record. |
externalId | string | Salesforce ExternalID field. |
dataSource | string | resolvable 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.
Param | Type | Default | Description |
---|---|---|---|
url | String | Relative or absolute URL to request from | |
options | Object | Request options | |
[options.method] | String | GET | HTTP method to use. Defaults to GET |
[options.headers] | Object | Object of request headers | |
[options.json] | Object | A JSON Object request body | |
[options.body] | String | HTTP body (in POST/PUT/PATCH methods) | |
callback | function | A 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).
Param | Type | Description |
---|---|---|
sObject | String | The sObject to retrieve |
id | String | The id of the record |
callback | function | A 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
Param | Type | Description |
---|---|---|
input | string | A string with unicode characters |
Example
fn((state) => {
const s = toUTF8("άνθρωποι");
console.log(s); // anthropoi
return state;
});
update
update(sObject, attrs) ⇒ Operation
Update an object.
Param | Type | Description |
---|---|---|
sObject | String | API name of the sObject. |
attrs | Object | Field attributes for the new object. |
Example
update('obj_name', {
attr1: "foo",
attr2: "bar"
})
upsert
upsert(sObject, externalId, attrs) ⇒ Operation
Upsert an object.
Param | Type | Description |
---|---|---|
sObject | String | API name of the sObject. |
externalId | String | ID. |
attrs | Object | Field 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.
Param | Type | Description |
---|---|---|
logical | boolean | a logical statement that will be evaluated. |
sObject | String | API name of the sObject. |
externalId | String | ID. |
attrs | Object | Field attributes for the new object. |
Example
upsertIf(true, 'obj_name', 'ext_id', {
attr1: "foo",
attr2: "bar"
})