From 4a69e0dbd549616bf15d5d5bad402e1d5c61b685 Mon Sep 17 00:00:00 2001
From: Rebbe Pod <66928914+RebbePod@users.noreply.github.com>
Date: Tue, 7 Jan 2025 23:00:42 -0500
Subject: [PATCH 1/2] Update dataPoller.js
gives an option to load data initially
---
.../main/default/lwc/dataPoller/dataPoller.js | 53 +++++++++++--------
1 file changed, 32 insertions(+), 21 deletions(-)
diff --git a/flow_screen_components/dataPoller/force-app/main/default/lwc/dataPoller/dataPoller.js b/flow_screen_components/dataPoller/force-app/main/default/lwc/dataPoller/dataPoller.js
index 83524c20a..678a37ba7 100644
--- a/flow_screen_components/dataPoller/force-app/main/default/lwc/dataPoller/dataPoller.js
+++ b/flow_screen_components/dataPoller/force-app/main/default/lwc/dataPoller/dataPoller.js
@@ -1,12 +1,14 @@
import { api, LightningElement } from 'lwc';
import getSobjects from '@salesforce/apex/DataPollerController.getSobjects';
import { FlowAttributeChangeEvent } from 'lightning/flowSupport';
+
export default class DataPoller extends LightningElement {
@api pollingFrequency = 3;
@api queryString;
-
@api newQueryString;
+ @api runInitialQueryImmediately = false;
+
_queryId;
@api
get queryId() {
@@ -14,32 +16,41 @@ export default class DataPoller extends LightningElement {
}
set queryId(value) {
this._queryId = value;
- this.newQueryString = this.queryString.replace('{Id}', value);
+ this.newQueryString = this.queryString?.replace('{Id}', value);
}
@api retrievedRecords = [];
@api error;
connectedCallback() {
+ if (!this.newQueryString && this.queryString) {
+ this.newQueryString = this.queryString;
+ }
+
this.dispatchEvent(new FlowAttributeChangeEvent('retrievedRecords', []));
- setInterval(function() {
- getSobjects({queryString : this.newQueryString}).then(
- result => {
- this.retrievedRecords = result;
- this.dispatchEvent(new FlowAttributeChangeEvent('retrievedRecords', this.retrievedRecords));
- }
- ).catch(
- error => {
- console.error('error', error);
- if(this.newQueryString) {
- this.error = error?.body?.message;
- this.dispatchEvent(new FlowAttributeChangeEvent('error', this.error?.body?.message));
- }
- }
- );
- }.bind(this), this.pollingFrequency * 1000
- )
-
+
+ if (this.runInitialQueryImmediately) {
+ this.executeQuery();
+ }
+
+ setInterval(this.executeQuery.bind(this), this.pollingFrequency * 1000);
}
-}
\ No newline at end of file
+ executeQuery() {
+ if (!this.newQueryString) {
+ console.error('Error: queryString or newQueryString is undefined');
+ return;
+ }
+
+ getSobjects({ queryString: this.newQueryString })
+ .then(result => {
+ this.retrievedRecords = result;
+ this.dispatchEvent(new FlowAttributeChangeEvent('retrievedRecords', this.retrievedRecords));
+ })
+ .catch(error => {
+ console.error('Error executing query:', error);
+ this.error = error?.body?.message;
+ this.dispatchEvent(new FlowAttributeChangeEvent('error', this.error));
+ });
+ }
+}
From 30c36b2b3a66b8e5daa48dde3f425f4ee0ebe954 Mon Sep 17 00:00:00 2001
From: Rebbe Pod <66928914+RebbePod@users.noreply.github.com>
Date: Tue, 7 Jan 2025 23:04:15 -0500
Subject: [PATCH 2/2] Update dataPoller.js-meta.xml
gives an option to load data initially
---
.../main/default/lwc/dataPoller/dataPoller.js-meta.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/flow_screen_components/dataPoller/force-app/main/default/lwc/dataPoller/dataPoller.js-meta.xml b/flow_screen_components/dataPoller/force-app/main/default/lwc/dataPoller/dataPoller.js-meta.xml
index 34d9a0ff3..9f6161ed1 100644
--- a/flow_screen_components/dataPoller/force-app/main/default/lwc/dataPoller/dataPoller.js-meta.xml
+++ b/flow_screen_components/dataPoller/force-app/main/default/lwc/dataPoller/dataPoller.js-meta.xml
@@ -13,6 +13,7 @@
+
-
\ No newline at end of file
+