diff --git a/lib/Adaptor.js b/lib/Adaptor.js index d05ed16..f9139b6 100644 --- a/lib/Adaptor.js +++ b/lib/Adaptor.js @@ -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); @@ -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 { diff --git a/package.json b/package.json index 7c4dae0..e72e9d7 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/Adaptor.js b/src/Adaptor.js index e283024..828aad6 100644 --- a/src/Adaptor.js +++ b/src/Adaptor.js @@ -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); @@ -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 {