Skip to content

Commit b86a408

Browse files
authored
61 32 dont emit empty results in trig (#62)
1 parent a99dd03 commit b86a408

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.6.0 (June 09, 2023)
2+
Added `Don't emit on empty results` checkbox in `Query` trigger
3+
14
## 2.5.1 (January 31, 2023)
25
* Fixed [issue](https://github.com/elasticio/salesforce-component-v2/issues/59) with 431 and 414 errors in `Get Updated Objects Polling` trigger: new configuration field `Selected Fields` added
36

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ This trigger allows you to interact with your data using SOQL.
102102

103103
* **SOQL Query** - Input field for your SOQL Query
104104
* **Output method** - dropdown list with options: `Emit all` - all found records will be emitted in one array `records`, and `Emit individually` - each found object will be emitted individual. Optional field, defaults to: `Emit individually`.
105+
* **Don't emit on empty results** - checkbox, optional. If selected, component will not produce empty messages when result is empty.
105106

106107
### Subscribe to platform events (REALTIME FLOWS ONLY)
107108
This trigger will subscribe for any platform Event using Salesforce streaming API.

component.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Customer relationship management (CRM) software & cloud computing from the leader in CRM solutions for businesses large & small.",
44
"docsUrl": "https://github.com/elasticio/salesforce-component-v2",
55
"url": "http://www.salesforce.com/",
6-
"version": "2.5.1",
6+
"version": "2.6.0",
77
"authClientTypes": [
88
"oauth2"
99
],
@@ -224,6 +224,14 @@
224224
"emitIndividually": "Emit individually"
225225
},
226226
"prompt": "Please select an output method. Defaults to: Emit individually"
227+
},
228+
"dontEmitOnEmptyResults": {
229+
"viewClass": "CheckBoxView",
230+
"label": "Don't emit on empty results",
231+
"required": false,
232+
"help": {
233+
"description": "If selected, component will not produce empty messages when result is empty."
234+
}
227235
}
228236
}
229237
},

lib/triggers/query.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ const { messages } = require('elasticio-node');
22
const { callJSForceMethod } = require('../helpers/wrapper');
33

44
const validEmitMethods = ['emitAll', 'emitIndividually'];
5+
const isDebugFlow = process.env.ELASTICIO_FLOW_TYPE === 'debug';
56

67
exports.process = async function processTrigger(msg, configuration) {
78
this.logger.info('Starting Query trigger');
8-
const { query, outputMethod = 'emitIndividually' } = configuration;
9+
const { query, outputMethod = 'emitIndividually', dontEmitOnEmptyResults } = configuration;
910
if (!validEmitMethods.includes(outputMethod)) throw new Error('Unsupported Output method');
1011
let records;
1112
try {
@@ -18,7 +19,16 @@ exports.process = async function processTrigger(msg, configuration) {
1819
throw new Error(error);
1920
}
2021
if (records.length === 0) {
21-
await this.emit('data', messages.newEmptyMessage());
22+
this.logger.info('No records found for provided Query');
23+
if (dontEmitOnEmptyResults) {
24+
if (isDebugFlow) {
25+
throw new Error(`No object found. Execution stopped.
26+
This error is only applicable to the Retrieve Sample.
27+
In flow executions there will be no error, just an execution skip.`);
28+
}
29+
} else {
30+
await this.emit('data', messages.newEmptyMessage());
31+
}
2232
} else if (outputMethod === 'emitAll') {
2333
this.logger.debug('Selected Output method Emit all');
2434
await this.emit('data', messages.newMessageWithBody({ records }));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"audit": "better-npm-audit audit --level high --production",
77
"pretest": "eslint lib spec spec-integration verifyCredentials.js --fix",
8-
"test": "mocha spec NODE_ENV=test --recursive --timeout 50000",
8+
"test": "mocha spec NODE_ENV=test --recursive --timeout 50000 --exit",
99
"integration-test": "nyc mocha --require spec-integration/mochaHooks.js spec-integration --recursive --timeout 50000"
1010
},
1111
"repository": {

0 commit comments

Comments
 (0)