@pipedream/salesforce_rest_api 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -0
- package/actions/add-contact-to-campaign/add-contact-to-campaign.mjs +25 -25
- package/actions/add-lead-to-campaign/add-lead-to-campaign.mjs +25 -24
- package/actions/common/base-create-update.mjs +108 -0
- package/actions/convert-soap-xml-to-json/convert-soap-xml-to-json.mjs +11 -3
- package/actions/create-account/create-account.mjs +33 -36
- package/actions/create-attachment/create-attachment.mjs +36 -50
- package/actions/create-campaign/create-campaign.mjs +41 -37
- package/actions/create-case/create-case.mjs +41 -37
- package/actions/create-casecomment/create-casecomment.mjs +26 -38
- package/actions/create-contact/create-contact.mjs +38 -35
- package/actions/create-event/create-event.mjs +57 -66
- package/actions/create-lead/create-lead.mjs +34 -42
- package/actions/create-note/create-note.mjs +24 -43
- package/actions/create-opportunity/create-opportunity.mjs +38 -47
- package/actions/create-record/create-record.mjs +49 -15
- package/actions/create-task/create-task.mjs +50 -42
- package/actions/create-user/create-user.mjs +33 -196
- package/actions/delete-opportunity/delete-opportunity.mjs +17 -13
- package/actions/delete-record/delete-record.mjs +18 -16
- package/actions/find-records/find-records.mjs +41 -26
- package/actions/insert-blob-data/insert-blob-data.mjs +3 -7
- package/actions/post-feed-to-chatter/post-feed-to-chatter.mjs +45 -20
- package/actions/search-string/search-string.mjs +22 -20
- package/actions/soql-search/soql-search.mjs +13 -8
- package/actions/sosl-search/sosl-search.mjs +19 -9
- package/actions/update-account/update-account.mjs +54 -41
- package/actions/update-contact/update-contact.mjs +59 -40
- package/actions/update-opportunity/update-opportunity.mjs +56 -54
- package/actions/update-record/update-record.mjs +67 -20
- package/common/all-sobjects.mjs +3812 -0
- package/common/constants-props.mjs +1539 -0
- package/common/props-async-options.mjs +154 -0
- package/common/props-utils.mjs +88 -31
- package/common/sobjects/account.mjs +349 -22
- package/common/sobjects/attachment.mjs +56 -17
- package/common/sobjects/campaign.mjs +125 -23
- package/common/sobjects/case.mjs +193 -13
- package/common/sobjects/caseComment.mjs +28 -4
- package/common/sobjects/contact.mjs +207 -43
- package/common/sobjects/event.mjs +218 -18
- package/common/sobjects/lead.mjs +245 -22
- package/common/sobjects/note.mjs +37 -14
- package/common/sobjects/opportunity.mjs +148 -22
- package/common/sobjects/task.mjs +240 -19
- package/common/sobjects/user.mjs +965 -0
- package/package.json +2 -2
- package/salesforce_rest_api.app.mjs +77 -254
- package/sources/common-webhook-methods.mjs +71 -0
- package/sources/common.mjs +85 -22
- package/sources/new-outbound-message/new-outbound-message.mjs +11 -3
- package/sources/new-record-instant/new-record-instant.mjs +77 -6
- package/sources/record-deleted-instant/record-deleted-instant.mjs +40 -5
- package/sources/record-updated-instant/record-updated-instant.mjs +168 -0
- package/actions/common/base.mjs +0 -18
- package/actions/find-create-record/find-create-record.mjs +0 -89
- package/actions/get-sobject-fields-values/get-sobject-fields-values.mjs +0 -57
- package/common/utils.mjs +0 -51
- package/sources/common-instant.mjs +0 -146
- package/sources/new-record/new-record.mjs +0 -91
- package/sources/object-updated/object-updated.mjs +0 -94
- package/sources/object-updated-instant/object-updated-instant.mjs +0 -36
- package/sources/record-deleted/record-deleted.mjs +0 -51
- package/sources/updated-field-on-record/updated-field-on-record.mjs +0 -161
- package/sources/updated-field-on-record-instant/updated-field-on-record-instant.mjs +0 -76
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import startCase from "lodash/startCase.js";
|
|
2
|
-
import common from "../common
|
|
2
|
+
import common from "../common.mjs";
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
...common,
|
|
6
6
|
type: "source",
|
|
7
7
|
name: "New Record (Instant, of Selectable Type)",
|
|
8
8
|
key: "salesforce_rest_api-new-record-instant",
|
|
9
|
-
description: "Emit new event
|
|
10
|
-
version: "0.0
|
|
9
|
+
description: "Emit new event when a record of the selected object type is created. [See the documentation](https://sforce.co/3yPSJZy)",
|
|
10
|
+
version: "0.1.0",
|
|
11
11
|
hooks: {
|
|
12
12
|
...common.hooks,
|
|
13
13
|
async deploy() {
|
|
@@ -15,7 +15,7 @@ export default {
|
|
|
15
15
|
const nameField = await this.salesforce.getNameFieldForObjectType(objectType);
|
|
16
16
|
this.setNameField(nameField);
|
|
17
17
|
|
|
18
|
-
// emit
|
|
18
|
+
// emit historical events
|
|
19
19
|
const { recentItems } = await this.salesforce.listSObjectTypeIds(objectType);
|
|
20
20
|
const ids = recentItems.map((item) => item.Id);
|
|
21
21
|
for (const id of ids.slice(-25)) {
|
|
@@ -26,13 +26,29 @@ export default {
|
|
|
26
26
|
"UserId": id,
|
|
27
27
|
},
|
|
28
28
|
};
|
|
29
|
-
this.
|
|
29
|
+
this.processWebhookEvent(event);
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
},
|
|
33
33
|
methods: {
|
|
34
34
|
...common.methods,
|
|
35
|
-
|
|
35
|
+
generateTimerMeta(item, fieldName) {
|
|
36
|
+
const { objectType } = this;
|
|
37
|
+
const {
|
|
38
|
+
CreatedDate: createdDate,
|
|
39
|
+
[fieldName]: name,
|
|
40
|
+
Id: id,
|
|
41
|
+
} = item;
|
|
42
|
+
const entityType = startCase(objectType);
|
|
43
|
+
const summary = `New ${entityType} created: ${name}`;
|
|
44
|
+
const ts = Date.parse(createdDate);
|
|
45
|
+
return {
|
|
46
|
+
id,
|
|
47
|
+
summary,
|
|
48
|
+
ts,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
generateWebhookMeta(data) {
|
|
36
52
|
const nameField = this.getNameField();
|
|
37
53
|
const { New: newObject } = data.body;
|
|
38
54
|
const {
|
|
@@ -52,5 +68,60 @@ export default {
|
|
|
52
68
|
getEventType() {
|
|
53
69
|
return "new";
|
|
54
70
|
},
|
|
71
|
+
async processTimerEvent(eventData) {
|
|
72
|
+
const {
|
|
73
|
+
paginate,
|
|
74
|
+
objectType,
|
|
75
|
+
setLatestDateCovered,
|
|
76
|
+
getObjectTypeColumns,
|
|
77
|
+
getNameField,
|
|
78
|
+
generateTimerMeta,
|
|
79
|
+
$emit: emit,
|
|
80
|
+
} = this;
|
|
81
|
+
|
|
82
|
+
const {
|
|
83
|
+
startTimestamp,
|
|
84
|
+
endTimestamp,
|
|
85
|
+
} = eventData;
|
|
86
|
+
|
|
87
|
+
const fieldName = getNameField();
|
|
88
|
+
const columns = getObjectTypeColumns();
|
|
89
|
+
|
|
90
|
+
const events = await paginate({
|
|
91
|
+
objectType,
|
|
92
|
+
startTimestamp,
|
|
93
|
+
endTimestamp,
|
|
94
|
+
columns,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const [
|
|
98
|
+
latestEvent,
|
|
99
|
+
] = events;
|
|
100
|
+
|
|
101
|
+
if (latestEvent?.CreatedDate) {
|
|
102
|
+
const latestDateCovered = new Date(latestEvent.CreatedDate);
|
|
103
|
+
latestDateCovered.setSeconds(0);
|
|
104
|
+
setLatestDateCovered(latestDateCovered.toISOString());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
Array.from(events)
|
|
108
|
+
.reverse()
|
|
109
|
+
.forEach((item) => {
|
|
110
|
+
const meta = generateTimerMeta(item, fieldName);
|
|
111
|
+
emit(item, meta);
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
async timerActivateHook() {
|
|
115
|
+
const {
|
|
116
|
+
objectType,
|
|
117
|
+
getObjectTypeDescription,
|
|
118
|
+
setObjectTypeColumns,
|
|
119
|
+
} = this;
|
|
120
|
+
|
|
121
|
+
const { fields } = await getObjectTypeDescription(objectType);
|
|
122
|
+
const columns = fields.map(({ name }) => name);
|
|
123
|
+
|
|
124
|
+
setObjectTypeColumns(columns);
|
|
125
|
+
},
|
|
55
126
|
},
|
|
56
127
|
};
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import startCase from "lodash/startCase.js";
|
|
2
|
-
|
|
3
|
-
import common from "../common-instant.mjs";
|
|
2
|
+
import common from "../common.mjs";
|
|
4
3
|
|
|
5
4
|
export default {
|
|
6
5
|
...common,
|
|
7
6
|
type: "source",
|
|
8
7
|
name: "New Deleted Record (Instant, of Selectable Type)",
|
|
9
8
|
key: "salesforce_rest_api-record-deleted-instant",
|
|
10
|
-
description: "Emit new event
|
|
11
|
-
version: "0.0
|
|
9
|
+
description: "Emit new event when a record of the selected object type is deleted. [See the documentation](https://sforce.co/3msDDEE)",
|
|
10
|
+
version: "0.1.0",
|
|
12
11
|
methods: {
|
|
13
12
|
...common.methods,
|
|
14
|
-
|
|
13
|
+
generateWebhookMeta(data) {
|
|
15
14
|
const nameField = this.getNameField();
|
|
16
15
|
const { Old: oldObject } = data.body;
|
|
17
16
|
const {
|
|
@@ -29,8 +28,44 @@ export default {
|
|
|
29
28
|
ts,
|
|
30
29
|
};
|
|
31
30
|
},
|
|
31
|
+
generateTimerMeta(item) {
|
|
32
|
+
const {
|
|
33
|
+
id,
|
|
34
|
+
deletedDate,
|
|
35
|
+
} = item;
|
|
36
|
+
const entityType = startCase(this.objectType);
|
|
37
|
+
const summary = `${entityType} deleted: ${id}`;
|
|
38
|
+
const ts = Date.parse(deletedDate);
|
|
39
|
+
return {
|
|
40
|
+
id,
|
|
41
|
+
summary,
|
|
42
|
+
ts,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
32
45
|
getEventType() {
|
|
33
46
|
return "deleted";
|
|
34
47
|
},
|
|
48
|
+
async processTimerEvent(eventData) {
|
|
49
|
+
const {
|
|
50
|
+
startTimestamp,
|
|
51
|
+
endTimestamp,
|
|
52
|
+
} = eventData;
|
|
53
|
+
const {
|
|
54
|
+
deletedRecords,
|
|
55
|
+
latestDateCovered,
|
|
56
|
+
} = await this.salesforce.getDeletedForObjectType(
|
|
57
|
+
this.objectType,
|
|
58
|
+
startTimestamp,
|
|
59
|
+
endTimestamp,
|
|
60
|
+
);
|
|
61
|
+
this.setLatestDateCovered(latestDateCovered);
|
|
62
|
+
|
|
63
|
+
// When a record is deleted, the `getDeleted` API only shows the ID of the
|
|
64
|
+
// deleted item and the date in which it was deleted.
|
|
65
|
+
deletedRecords.forEach((item) => {
|
|
66
|
+
const meta = this.generateTimerMeta(item);
|
|
67
|
+
this.$emit(item, meta);
|
|
68
|
+
});
|
|
69
|
+
},
|
|
35
70
|
},
|
|
36
71
|
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import startCase from "lodash/startCase.js";
|
|
2
|
+
import common from "../common.mjs";
|
|
3
|
+
import constants from "../../common/constants.mjs";
|
|
4
|
+
const { salesforce } = common.props;
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
...common,
|
|
8
|
+
type: "source",
|
|
9
|
+
name: "New Updated Record (Instant, of Selectable Type)",
|
|
10
|
+
key: "salesforce_rest_api-record-updated-instant",
|
|
11
|
+
description: "Emit new event when a record of the selected type is updated. [See the documentation](https://sforce.co/3yPSJZy)",
|
|
12
|
+
version: "0.2.0",
|
|
13
|
+
props: {
|
|
14
|
+
...common.props,
|
|
15
|
+
fields: {
|
|
16
|
+
propDefinition: [
|
|
17
|
+
salesforce,
|
|
18
|
+
"field",
|
|
19
|
+
({ objectType }) => ({
|
|
20
|
+
objectType,
|
|
21
|
+
filter: ({ updateable }) => updateable,
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
label: "Fields To Watch",
|
|
25
|
+
type: "string[]",
|
|
26
|
+
optional: true,
|
|
27
|
+
description: "If specified, events will only be emitted if at least one of the selected fields is updated. This filter is only available when a webhook is created successfully.",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
methods: {
|
|
31
|
+
...common.methods,
|
|
32
|
+
generateWebhookMeta(data) {
|
|
33
|
+
const nameField = this.getNameField();
|
|
34
|
+
const { New: newObject } = data.body;
|
|
35
|
+
const {
|
|
36
|
+
LastModifiedDate: lastModifiedDate,
|
|
37
|
+
Id: id,
|
|
38
|
+
[nameField]: name,
|
|
39
|
+
} = newObject;
|
|
40
|
+
const entityType = startCase(this.objectType);
|
|
41
|
+
const summary = `${entityType} updated: ${name}`;
|
|
42
|
+
const ts = Date.parse(lastModifiedDate);
|
|
43
|
+
const compositeId = `${id}-${ts}`;
|
|
44
|
+
return {
|
|
45
|
+
id: compositeId,
|
|
46
|
+
summary,
|
|
47
|
+
ts,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
generateTimerMeta(item, fieldName) {
|
|
51
|
+
const { objectType } = this;
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
LastModifiedDate: lastModifiedDate,
|
|
55
|
+
[fieldName]: name,
|
|
56
|
+
Id: id,
|
|
57
|
+
} = item;
|
|
58
|
+
|
|
59
|
+
const entityType = startCase(objectType);
|
|
60
|
+
const summary = `${entityType} updated: ${name}`;
|
|
61
|
+
const ts = Date.parse(lastModifiedDate);
|
|
62
|
+
return {
|
|
63
|
+
id: `${id}-${ts}`,
|
|
64
|
+
summary,
|
|
65
|
+
ts,
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
getEventType() {
|
|
69
|
+
return "updated";
|
|
70
|
+
},
|
|
71
|
+
isEventRelevant(changedFields) {
|
|
72
|
+
const { fields } = this;
|
|
73
|
+
return fields?.length
|
|
74
|
+
? Object.keys(changedFields).some((key) => fields.includes(key))
|
|
75
|
+
: true;
|
|
76
|
+
},
|
|
77
|
+
getChangedFields(body) {
|
|
78
|
+
return Object.entries(body.New).filter(([
|
|
79
|
+
key,
|
|
80
|
+
value,
|
|
81
|
+
]) => {
|
|
82
|
+
const oldValue = body.Old[key];
|
|
83
|
+
return (
|
|
84
|
+
value !== undefined
|
|
85
|
+
&& oldValue !== undefined
|
|
86
|
+
&& JSON.stringify(value) !== JSON.stringify(oldValue)
|
|
87
|
+
);
|
|
88
|
+
})
|
|
89
|
+
.reduce((obj, [
|
|
90
|
+
key,
|
|
91
|
+
value,
|
|
92
|
+
]) => {
|
|
93
|
+
obj[key] = {
|
|
94
|
+
old: body.Old[key],
|
|
95
|
+
new: value,
|
|
96
|
+
};
|
|
97
|
+
return obj;
|
|
98
|
+
}, {});
|
|
99
|
+
},
|
|
100
|
+
processWebhookEvent(event) {
|
|
101
|
+
const { body } = event;
|
|
102
|
+
const changedFields = this.getChangedFields(body);
|
|
103
|
+
if (this.isEventRelevant(changedFields)) {
|
|
104
|
+
const meta = this.generateWebhookMeta(event);
|
|
105
|
+
this.$emit({
|
|
106
|
+
...body,
|
|
107
|
+
changedFields,
|
|
108
|
+
}, meta);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
async processTimerEvent(eventData) {
|
|
112
|
+
const {
|
|
113
|
+
getNameField,
|
|
114
|
+
getObjectTypeColumns,
|
|
115
|
+
paginate,
|
|
116
|
+
objectType,
|
|
117
|
+
setLatestDateCovered,
|
|
118
|
+
generateTimerMeta,
|
|
119
|
+
$emit: emit,
|
|
120
|
+
} = this;
|
|
121
|
+
|
|
122
|
+
const {
|
|
123
|
+
startTimestamp,
|
|
124
|
+
endTimestamp,
|
|
125
|
+
} = eventData;
|
|
126
|
+
|
|
127
|
+
const fieldName = getNameField();
|
|
128
|
+
const columns = getObjectTypeColumns();
|
|
129
|
+
|
|
130
|
+
const events = await paginate({
|
|
131
|
+
objectType,
|
|
132
|
+
startTimestamp,
|
|
133
|
+
endTimestamp,
|
|
134
|
+
columns,
|
|
135
|
+
dateFieldName: constants.FIELD_NAME.LAST_MODIFIED_DATE,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const [
|
|
139
|
+
latestEvent,
|
|
140
|
+
] = events;
|
|
141
|
+
|
|
142
|
+
if (latestEvent?.LastModifiedDate) {
|
|
143
|
+
const latestDateCovered = new Date(latestEvent.LastModifiedDate);
|
|
144
|
+
latestDateCovered.setSeconds(0);
|
|
145
|
+
setLatestDateCovered(latestDateCovered.toISOString());
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
Array.from(events)
|
|
149
|
+
.reverse()
|
|
150
|
+
.forEach((item) => {
|
|
151
|
+
const meta = generateTimerMeta(item, fieldName);
|
|
152
|
+
emit(item, meta);
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
async timerActivateHook() {
|
|
156
|
+
const {
|
|
157
|
+
objectType,
|
|
158
|
+
getObjectTypeDescription,
|
|
159
|
+
setObjectTypeColumns,
|
|
160
|
+
} = this;
|
|
161
|
+
|
|
162
|
+
const { fields } = await getObjectTypeDescription(objectType);
|
|
163
|
+
const columns = fields.map(({ name }) => name);
|
|
164
|
+
|
|
165
|
+
setObjectTypeColumns(columns);
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
};
|
package/actions/common/base.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import salesforce from "../../salesforce_rest_api.app.mjs";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
props: {
|
|
5
|
-
salesforce,
|
|
6
|
-
},
|
|
7
|
-
methods: {
|
|
8
|
-
additionalProps(selector, sobject) {
|
|
9
|
-
if (!selector || !sobject) {
|
|
10
|
-
return {};
|
|
11
|
-
}
|
|
12
|
-
return selector.reduce((props, prop) => ({
|
|
13
|
-
...props,
|
|
14
|
-
[prop]: sobject[prop],
|
|
15
|
-
}), {});
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { ConfigurationError } from "@pipedream/platform";
|
|
2
|
-
import salesForceRestApi from "../../salesforce_rest_api.app.mjs";
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
key: "salesforce_rest_api-find-create-record",
|
|
6
|
-
name: "Get Field Values from Object Record and optionally create one is none is found. ",
|
|
7
|
-
description:
|
|
8
|
-
"Finds a specified Salesforce record by a field. Optionally, create one if none is found. [API Docs](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_get_field_values.htm)",
|
|
9
|
-
version: "0.1.5",
|
|
10
|
-
type: "action",
|
|
11
|
-
props: {
|
|
12
|
-
salesForceRestApi,
|
|
13
|
-
sobjectType: {
|
|
14
|
-
propDefinition: [
|
|
15
|
-
salesForceRestApi,
|
|
16
|
-
"objectType",
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
sobjectId: {
|
|
20
|
-
propDefinition: [
|
|
21
|
-
salesForceRestApi,
|
|
22
|
-
"sobjectId",
|
|
23
|
-
(c) => ({
|
|
24
|
-
objectType: c.sobjectType,
|
|
25
|
-
}),
|
|
26
|
-
],
|
|
27
|
-
description:
|
|
28
|
-
"ID of the Salesforce standard object to get field values from.",
|
|
29
|
-
},
|
|
30
|
-
sobjectFields: {
|
|
31
|
-
type: "string[]",
|
|
32
|
-
label: "Fields to get values from",
|
|
33
|
-
description:
|
|
34
|
-
"list of the Salesforce standard object's fields to get values from.",
|
|
35
|
-
},
|
|
36
|
-
createIfNotFound: {
|
|
37
|
-
type: "boolean",
|
|
38
|
-
label: "Create new object",
|
|
39
|
-
description: "Create a new object if none is found",
|
|
40
|
-
reloadProps: true,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
async additionalProps() {
|
|
44
|
-
return {
|
|
45
|
-
sobject: {
|
|
46
|
-
type: "object",
|
|
47
|
-
label: "Salesforce standard object",
|
|
48
|
-
description: `Data of the Salesforce standard object record to create.
|
|
49
|
-
Salesforce standard objects are described in [Standard Objects](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_list.htm) section of the [SOAP API Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_intro.htm).`,
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
async run({ $ }) {
|
|
54
|
-
const {
|
|
55
|
-
sobjectType,
|
|
56
|
-
sobjectId,
|
|
57
|
-
sobjectFields,
|
|
58
|
-
sobject,
|
|
59
|
-
createIfNotFound,
|
|
60
|
-
} = this;
|
|
61
|
-
let data;
|
|
62
|
-
try {
|
|
63
|
-
data = await this.salesForceRestApi.getSObject(
|
|
64
|
-
sobjectType,
|
|
65
|
-
sobjectId,
|
|
66
|
-
sobjectFields && {
|
|
67
|
-
fields: sobjectFields.join(","),
|
|
68
|
-
},
|
|
69
|
-
);
|
|
70
|
-
} catch (error) {
|
|
71
|
-
if (!createIfNotFound) throw new ConfigurationError("Record not found");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (createIfNotFound && !data) {
|
|
75
|
-
const response = await this.salesForceRestApi.createObject(
|
|
76
|
-
sobjectType,
|
|
77
|
-
sobject,
|
|
78
|
-
);
|
|
79
|
-
response && $.export(
|
|
80
|
-
"$summary", "Record successfully created",
|
|
81
|
-
);
|
|
82
|
-
return response;
|
|
83
|
-
}
|
|
84
|
-
if (data) {
|
|
85
|
-
$.export("$summary", "Record found!");
|
|
86
|
-
}
|
|
87
|
-
return data;
|
|
88
|
-
},
|
|
89
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import salesforce from "../../salesforce_rest_api.app.mjs";
|
|
2
|
-
import { toSingleLineString } from "../../common/utils.mjs";
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
key: "salesforce_rest_api-get-sobject-fields-values",
|
|
6
|
-
name: "Get Field Values from a Standard Object Record",
|
|
7
|
-
description: toSingleLineString(`
|
|
8
|
-
Retrieve field values from a record. You can specify the fields you want to retrieve.
|
|
9
|
-
See [docs](https://developer.salesforce.com/docs/atlas.en-us.228.0.api_rest.meta/api_rest/dome_get_field_values.htm)
|
|
10
|
-
`),
|
|
11
|
-
version: "0.2.7",
|
|
12
|
-
type: "action",
|
|
13
|
-
props: {
|
|
14
|
-
salesforce,
|
|
15
|
-
objectType: {
|
|
16
|
-
propDefinition: [
|
|
17
|
-
salesforce,
|
|
18
|
-
"objectType",
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
sobjectId: {
|
|
22
|
-
propDefinition: [
|
|
23
|
-
salesforce,
|
|
24
|
-
"sobjectId",
|
|
25
|
-
(c) => ({
|
|
26
|
-
objectType: c.objectType,
|
|
27
|
-
}),
|
|
28
|
-
],
|
|
29
|
-
},
|
|
30
|
-
fields: {
|
|
31
|
-
type: "string[]",
|
|
32
|
-
label: "SObject Fields",
|
|
33
|
-
description: "List of fields of the Standard object to get values from",
|
|
34
|
-
propDefinition: [
|
|
35
|
-
salesforce,
|
|
36
|
-
"field",
|
|
37
|
-
(c) => ({
|
|
38
|
-
objectType: c.objectType,
|
|
39
|
-
}),
|
|
40
|
-
],
|
|
41
|
-
optional: true,
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
async run({ $ }) {
|
|
45
|
-
const params = {};
|
|
46
|
-
if (this.fields?.length > 0) {
|
|
47
|
-
params.fields = this.fields.join(",");
|
|
48
|
-
}
|
|
49
|
-
const response = await this.salesforce.getRecordFieldValues(this.objectType, {
|
|
50
|
-
$,
|
|
51
|
-
id: this.sobjectId,
|
|
52
|
-
params,
|
|
53
|
-
});
|
|
54
|
-
$.export("$summary", `Retrieved ${this.objectType} field values`);
|
|
55
|
-
return response;
|
|
56
|
-
},
|
|
57
|
-
};
|
package/common/utils.mjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A utility function that accepts a string as an argument and reformats it in
|
|
3
|
-
* order to remove newline characters and consecutive spaces. Useful when
|
|
4
|
-
* dealing with very long templated strings that are split into multiple lines.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* // returns "This is a much cleaner string"
|
|
8
|
-
* toSingleLineString(`
|
|
9
|
-
* This is a much
|
|
10
|
-
* cleaner string
|
|
11
|
-
* `);
|
|
12
|
-
*
|
|
13
|
-
* @param {string} multiLineString the input string to reformat
|
|
14
|
-
* @returns a formatted string based on the content of the input argument,
|
|
15
|
-
* without newlines and multiple spaces
|
|
16
|
-
* Source: {@linkcode ../aws/sources/common/utils.mjs utils.mjs}
|
|
17
|
-
*/
|
|
18
|
-
function toSingleLineString(multiLineString) {
|
|
19
|
-
return multiLineString
|
|
20
|
-
.trim()
|
|
21
|
-
.replace(/\n/g, " ")
|
|
22
|
-
.replace(/\s{2,}/g, " ");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const removeNullEntries = (obj) =>
|
|
26
|
-
obj && Object.entries(obj).reduce((acc, [
|
|
27
|
-
key,
|
|
28
|
-
value,
|
|
29
|
-
]) => {
|
|
30
|
-
const isNumber = typeof value === "number";
|
|
31
|
-
const isBoolean = typeof value === "boolean";
|
|
32
|
-
const isNotEmpyString = typeof value === "string" && value.trim() !== "";
|
|
33
|
-
const isNotEmptyArray = Array.isArray(value) && value.length;
|
|
34
|
-
const isNotEmptyObject =
|
|
35
|
-
typeof value === "object" &&
|
|
36
|
-
value !== null &&
|
|
37
|
-
!Array.isArray(value) &&
|
|
38
|
-
Object.keys(value).length !== 0;
|
|
39
|
-
isNotEmptyObject && (value = removeNullEntries(value));
|
|
40
|
-
return ((value || value === false) &&
|
|
41
|
-
(isNotEmpyString || isNotEmptyArray || isNotEmptyObject || isBoolean || isNumber))
|
|
42
|
-
? {
|
|
43
|
-
...acc,
|
|
44
|
-
[key]: value,
|
|
45
|
-
}
|
|
46
|
-
: acc;
|
|
47
|
-
}, {});
|
|
48
|
-
|
|
49
|
-
export {
|
|
50
|
-
toSingleLineString, removeNullEntries,
|
|
51
|
-
};
|