Skip to content

Commit 68ddc67

Browse files
committed
Upsert Record update with external id field
1 parent b00986f commit 68ddc67

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

components/salesforce_rest_api/actions/upsert-record/upsert-record.mjs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ export default {
2020
description: "The type of object to create a record of",
2121
reloadProps: true,
2222
},
23-
externalIdFieldName: {
24-
type: "string",
25-
label: "External ID Field",
26-
description: "The name of the field used as the external ID. If a record exists with this field having the value specified in `External ID Value`, it will be updated, otherwise a new record will be created.",
27-
},
28-
externalIdValue: {
29-
type: "string",
30-
label: "External ID Value",
31-
description: "The value of the external ID field specified above. If a record exists with this value, it will be updated, otherwise a new record will be created.",
32-
}
3323
},
3424
methods: {
3525
getAdditionalFields,
@@ -43,6 +33,11 @@ export default {
4333
return field.createable && field.updateable && !field.nillable && !field.defaultedOnCreate;
4434
});
4535

36+
const externalIdFieldOptions = fields.filter(field => field.externalId).map(({ label, name}) => ({
37+
label,
38+
value: name
39+
}));
40+
4641
const requiredFieldProps = this.convertFieldsToProps(requiredFields);
4742

4843
return {
@@ -51,6 +46,23 @@ export default {
5146
alertType: "info",
5247
content: `[See the documentation](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_${objectType.toLowerCase()}.htm) for information on all available fields.`,
5348
},
49+
externalIdFieldName: {
50+
type: "string",
51+
label: "External ID Field",
52+
description: "The field to use as the external ID to identify the record.",
53+
options: externalIdFieldOptions,
54+
},
55+
externalIdFieldValue: {
56+
type: "string",
57+
label: "External ID Value",
58+
description: "The value of the external ID field selected above. If a record with this value exists, it will be updated, otherwise a new one will be created.",
59+
},
60+
updateOnly: {
61+
type: "boolean",
62+
label: "Update Only",
63+
description: "If enabled, the action will only update an existing record, but not create one.",
64+
optional: true,
65+
},
5466
...requiredFieldProps,
5567
additionalFields,
5668
};
@@ -66,13 +78,17 @@ export default {
6678
additionalFields,
6779
externalIdFieldName,
6880
externalIdValue,
81+
updateOnly,
6982
...data
7083
} = this;
7184
/* eslint-enable no-unused-vars */
7285
const response = await salesforce.upsertRecord(objectType, {
7386
$,
7487
externalIdFieldName,
7588
externalIdValue,
89+
params: {
90+
updateOnly
91+
},
7692
data: {
7793
...data,
7894
...getData(),

0 commit comments

Comments
 (0)