Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
allow noOp for empty array during bulk
Browse files Browse the repository at this point in the history
  • Loading branch information
taylordowns2000 committed Jul 7, 2018
1 parent 39bc4c1 commit 1df83d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 8 additions & 1 deletion lib/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,16 @@ var query = exports.query = (0, _lodashFp.curry)(function (qs, state) {
var bulk = exports.bulk = (0, _lodashFp.curry)(function (sObject, operation, options, fun, state) {
var connection = state.connection,
references = state.references;
var failOnError = options.failOnError,
allowNoOp = options.allowNoOp;

var finalAttrs = fun(state);

if (allowNoOp && finalAttrs.length === 0) {
console.info('No items in ' + sObject + ' array. Skipping bulk ' + operation + ' operation.');
return state;
}

console.info('Creating bulk ' + operation + ' job for ' + sObject, finalAttrs);
var job = connection.bulk.createJob(sObject, operation, options);

Expand Down Expand Up @@ -265,7 +272,7 @@ var bulk = exports.bulk = (0, _lodashFp.curry)(function (sObject, operation, opt
return item.success === false;
});

if (options.failOnError && errors.length > 0) {
if (failOnError && errors.length > 0) {
console.error("Errors detected:");
throw res;
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "language-salesforce",
"version": "1.0.0",
"version": "1.0.1",
"description": "Salesforce Language Pack for OpenFn",
"main": "lib/index.js",
"scripts": {
Expand Down
10 changes: 8 additions & 2 deletions src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ export const query = curry(function(qs, state) {
* @returns {Operation}
*/
export const bulk = curry(function(sObject, operation, options, fun, state) {
let {connection, references} = state;
let { connection, references } = state;
let { failOnError, allowNoOp } = options;
const finalAttrs = fun(state);

if (allowNoOp && finalAttrs.length === 0) {
console.info(`No items in ${sObject} array. Skipping bulk ${operation} operation.`)
return state;
}

console.info(`Creating bulk ${operation} job for ${sObject}`, finalAttrs);
const job = connection.bulk.createJob(sObject, operation, options);

Expand Down Expand Up @@ -117,7 +123,7 @@ export const bulk = curry(function(sObject, operation, options, fun, state) {
return item.success === false
})

if (options.failOnError && errors.length > 0) {
if (failOnError && errors.length > 0) {
console.error("Errors detected:");
throw res;
} else {
Expand Down

0 comments on commit 1df83d1

Please sign in to comment.