@pipedream/salesforce_rest_api 1.2.1 → 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.
Files changed (64) hide show
  1. package/README.md +92 -0
  2. package/actions/add-contact-to-campaign/add-contact-to-campaign.mjs +25 -25
  3. package/actions/add-lead-to-campaign/add-lead-to-campaign.mjs +25 -24
  4. package/actions/common/base-create-update.mjs +108 -0
  5. package/actions/convert-soap-xml-to-json/convert-soap-xml-to-json.mjs +11 -3
  6. package/actions/create-account/create-account.mjs +33 -36
  7. package/actions/create-attachment/create-attachment.mjs +36 -50
  8. package/actions/create-campaign/create-campaign.mjs +41 -37
  9. package/actions/create-case/create-case.mjs +41 -37
  10. package/actions/create-casecomment/create-casecomment.mjs +26 -38
  11. package/actions/create-contact/create-contact.mjs +38 -35
  12. package/actions/create-event/create-event.mjs +57 -66
  13. package/actions/create-lead/create-lead.mjs +34 -42
  14. package/actions/create-note/create-note.mjs +24 -43
  15. package/actions/create-opportunity/create-opportunity.mjs +38 -47
  16. package/actions/create-record/create-record.mjs +49 -15
  17. package/actions/create-task/create-task.mjs +50 -42
  18. package/actions/create-user/create-user.mjs +33 -196
  19. package/actions/delete-opportunity/delete-opportunity.mjs +17 -13
  20. package/actions/delete-record/delete-record.mjs +18 -16
  21. package/actions/find-records/find-records.mjs +41 -26
  22. package/actions/insert-blob-data/insert-blob-data.mjs +3 -7
  23. package/actions/post-feed-to-chatter/post-feed-to-chatter.mjs +45 -20
  24. package/actions/search-string/search-string.mjs +22 -20
  25. package/actions/soql-search/soql-search.mjs +13 -8
  26. package/actions/sosl-search/sosl-search.mjs +19 -9
  27. package/actions/update-account/update-account.mjs +54 -41
  28. package/actions/update-contact/update-contact.mjs +59 -40
  29. package/actions/update-opportunity/update-opportunity.mjs +56 -54
  30. package/actions/update-record/update-record.mjs +67 -20
  31. package/common/all-sobjects.mjs +3812 -0
  32. package/common/constants-props.mjs +1539 -0
  33. package/common/props-async-options.mjs +154 -0
  34. package/common/props-utils.mjs +88 -31
  35. package/common/sobjects/account.mjs +349 -22
  36. package/common/sobjects/attachment.mjs +56 -17
  37. package/common/sobjects/campaign.mjs +125 -23
  38. package/common/sobjects/case.mjs +193 -13
  39. package/common/sobjects/caseComment.mjs +28 -4
  40. package/common/sobjects/contact.mjs +207 -43
  41. package/common/sobjects/event.mjs +218 -18
  42. package/common/sobjects/lead.mjs +245 -22
  43. package/common/sobjects/note.mjs +37 -14
  44. package/common/sobjects/opportunity.mjs +148 -22
  45. package/common/sobjects/task.mjs +240 -19
  46. package/common/sobjects/user.mjs +965 -0
  47. package/package.json +2 -2
  48. package/salesforce_rest_api.app.mjs +72 -249
  49. package/sources/common-webhook-methods.mjs +71 -0
  50. package/sources/common.mjs +85 -22
  51. package/sources/new-outbound-message/new-outbound-message.mjs +11 -3
  52. package/sources/new-record-instant/new-record-instant.mjs +77 -6
  53. package/sources/record-deleted-instant/record-deleted-instant.mjs +40 -5
  54. package/sources/record-updated-instant/record-updated-instant.mjs +137 -5
  55. package/actions/common/base.mjs +0 -18
  56. package/actions/find-create-record/find-create-record.mjs +0 -89
  57. package/actions/get-sobject-fields-values/get-sobject-fields-values.mjs +0 -57
  58. package/common/utils.mjs +0 -51
  59. package/sources/common-instant.mjs +0 -146
  60. package/sources/new-record/new-record.mjs +0 -91
  61. package/sources/record-deleted/record-deleted.mjs +0 -51
  62. package/sources/record-updated/record-updated.mjs +0 -94
  63. package/sources/updated-field-on-record/updated-field-on-record.mjs +0 -161
  64. package/sources/updated-field-on-record-instant/updated-field-on-record-instant.mjs +0 -76
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ # Overview
2
+
3
+ The Salesforce (REST API) provides a powerful platform for creating and managing customer relationships with a wide array of features like data manipulation, querying, and complex automation. With Pipedream's serverless execution, you can create workflows that automate your sales processes, sync data with other platforms, enhance customer engagement, and trigger actions based on specific events. Dive into Salesforce data, streamline lead management, track customer interactions, and push or pull data to or from Salesforce seamlessly.
4
+
1
5
  # Getting Started
2
6
 
3
7
  You can install the Pipedream Salesforce app in the [Accounts](https://pipedream.com/accounts) section of your Pipedream account, or directly in a workflow.
@@ -65,6 +69,24 @@ If you'd like to utilize Pipedream's webhook triggers, you will need to add the
65
69
 
66
70
  11. You should now be able to use the Salesforce integration along with the webhook triggers if you configured the required permissions above.
67
71
 
72
+ # Example Use Cases
73
+
74
+ ## **Synchronization between Salesforce and External Databases**
75
+
76
+ Synchronize Salesforce with external databases to ensure data accuracy and consistency without manual effort.
77
+
78
+ ## **Real-Time Customer Support Notifications**
79
+
80
+ Improve customer service responsiveness by triggering real-time notifications to support teams when new tickets are created.
81
+
82
+ ## **Lead Scoring and Engagement Automation**
83
+
84
+ Streamline lead management by automatically scoring and engaging leads through personalized campaigns, enhancing conversion rates.
85
+
86
+ ## **Dynamic Inventory Management**
87
+
88
+ Keep inventory levels accurate and responsive to sales activity by updating Salesforce in real-time based on e-commerce data.
89
+
68
90
 
69
91
  # Troubleshooting
70
92
 
@@ -103,3 +125,73 @@ If you happen to stumble on the error: `UNKNOWN_EXCEPTION: admin operation alrea
103
125
  15. Back to the Pipedream Workflow, create a new step with the **Salesforce Convert SOAP Object** action.
104
126
  16. In the **XML Soap Object** field, select the path from the trigger or type in `{{steps.trigger.event.body}}`.
105
127
  17. That's it! You can now deploy the workflow and you will receive instant updates from Salesforce.
128
+
129
+ ## API Errors
130
+
131
+ Below is a list of potential HTTP response status codes with their corresponding causes:
132
+
133
+ ### **400**
134
+
135
+ The request couldn't be understood, usually because the JSON or XML body contains an error.
136
+
137
+ ### **401**
138
+
139
+ The session ID or OAuth token used has expired or is invalid. The response body contains the message and errorCode.
140
+
141
+ ### **403**
142
+
143
+ The request has been refused. Check that the logged-in user has appropriate permissions. If the error code is REQUEST_LIMIT_EXCEEDED, the API request limits in your org have been exceeded.
144
+
145
+ ### **404**
146
+
147
+ The requested resource couldn't be found. Check the URI for errors, and ensure there are no sharing issues.
148
+
149
+ ### **405**
150
+
151
+ The method specified isn’t allowed for the resource indicated in the URI.
152
+
153
+ ### **409**
154
+
155
+ The request couldn’t be completed due to a conflict with the current state of the resource. Ensure the API version is compatible with the resource requested.
156
+
157
+ ### **410**
158
+
159
+ The requested resource has been retired or removed. Update or delete references to the resource.
160
+
161
+ ### **412**
162
+
163
+ The request wasn't executed because it didn't meet one or more preconditions specified in the request headers.
164
+
165
+
166
+ ### **414**
167
+
168
+ The length of the URI exceeds the 16,384-byte limit.
169
+
170
+ ### **415**
171
+
172
+ The entity in the request is in a format that's not supported by the specified method.
173
+
174
+ ### **420**
175
+
176
+ Salesforce Edge doesn’t have routing information for the request host. Contact Salesforce Customer Support.
177
+
178
+ ### **428**
179
+
180
+ The request wasn’t executed because it wasn't conditional. Add a Conditional Request Header like If-Match to the request.
181
+
182
+ ### **431**
183
+
184
+ The combined length of the URI and headers exceeds the 16,384-byte limit.
185
+
186
+ ### **500**
187
+
188
+ An error within Lightning Platform has occurred, preventing request completion. Contact Salesforce Customer Support.
189
+
190
+ ### **502**
191
+
192
+ Salesforce Edge couldn’t communicate successfully with the Salesforce instance.
193
+
194
+ ### **503**
195
+
196
+ The server is currently unable to handle the request, typically due to maintenance or being overloaded.
197
+
@@ -1,52 +1,52 @@
1
- import salesForceRestApi from "../../salesforce_rest_api.app.mjs";
2
- import {
3
- removeNullEntries, toSingleLineString,
4
- } from "../../common/utils.mjs";
1
+ import salesforce from "../../salesforce_rest_api.app.mjs";
5
2
  import constants from "../../common/constants.mjs";
6
3
 
7
4
  export default {
8
5
  key: "salesforce_rest_api-add-contact-to-campaign",
9
6
  name: "Add Contact to Campaign",
10
- description: toSingleLineString(`
11
- Adds an existing contact to an existing campaign.
12
- See [Event SObject](https://developer.salesforce.com/docs/atlas.en-us.228.0.object_reference.meta/object_reference/sforce_api_objects_campaignmember.htm)
13
- and [Create Record](https://developer.salesforce.com/docs/atlas.en-us.228.0.api_rest.meta/api_rest/dome_sobject_create.htm)
14
- `),
15
- version: "0.0.6",
7
+ description: "Adds an existing contact to an existing campaign. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.228.0.object_reference.meta/object_reference/sforce_api_objects_campaignmember.htm)",
8
+ version: "0.1.0",
16
9
  type: "action",
17
10
  props: {
18
- salesForceRestApi,
11
+ salesforce,
19
12
  campaignId: {
20
13
  propDefinition: [
21
- salesForceRestApi,
22
- "sobjectId",
14
+ salesforce,
15
+ "recordId",
23
16
  () => ({
24
- objectType: constants.OBJECT_TYPE.CAMPAIGN,
17
+ objType: "Campaign",
18
+ nameField: "Name",
25
19
  }),
26
20
  ],
27
21
  label: "Campaign ID",
28
- description: "ID of the Campaign to which this Lead is associated.",
22
+ description: "The Campaign to add a Contact to.",
29
23
  },
30
24
  contactId: {
31
25
  propDefinition: [
32
- salesForceRestApi,
33
- "sobjectId",
26
+ salesforce,
27
+ "recordId",
34
28
  () => ({
35
- objectType: constants.OBJECT_TYPE.CONTACT,
29
+ objType: "Contact",
30
+ nameField: "Name",
36
31
  }),
37
32
  ],
38
33
  label: "Contact ID",
39
- description: "ID of the Contact who is associated with a Campaign.",
34
+ description: "The Contact to add to the selected Campaign.",
40
35
  },
41
36
  },
42
37
  async run({ $ }) {
43
- const data = removeNullEntries({
44
- CampaignId: this.campaignId,
45
- ContactId: this.contactId,
38
+ const {
39
+ salesforce, campaignId, contactId,
40
+ } = this;
41
+ const response = await salesforce.createObject({
42
+ $,
43
+ objectType: constants.OBJECT_TYPE.CAMPAIGN_MEMBER,
44
+ data: {
45
+ CampaignId: campaignId,
46
+ ContactId: contactId,
47
+ },
46
48
  });
47
- const response = await this.salesForceRestApi
48
- .createObject(constants.OBJECT_TYPE.CAMPAIGN_MEMBER, data);
49
- response && $.export("$summary", "Successfully added contact to campaign");
49
+ $.export("$summary", `Successfully added contact (ID: ${contactId}) to campaign (ID: ${campaignId})`);
50
50
  return response;
51
51
  },
52
52
  };
@@ -1,51 +1,52 @@
1
- import salesForceRestApi from "../../salesforce_rest_api.app.mjs";
2
- import {
3
- removeNullEntries, toSingleLineString,
4
- } from "../../common/utils.mjs";
1
+ import salesforce from "../../salesforce_rest_api.app.mjs";
5
2
  import constants from "../../common/constants.mjs";
6
3
 
7
4
  export default {
8
5
  key: "salesforce_rest_api-add-lead-to-campaign",
9
6
  name: "Add Lead to Campaign",
10
- description: toSingleLineString(`
11
- Adds an existing lead to an existing campaign.
12
- See [Event SObject](https://developer.salesforce.com/docs/atlas.en-us.228.0.object_reference.meta/object_reference/sforce_api_objects_campaignmember.htm)
13
- and [Create Record](https://developer.salesforce.com/docs/atlas.en-us.228.0.api_rest.meta/api_rest/dome_sobject_create.htm)
14
- `),
15
- version: "0.0.6",
7
+ description: "Adds an existing lead to an existing campaign. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.228.0.object_reference.meta/object_reference/sforce_api_objects_campaignmember.htm)",
8
+ version: "0.1.0",
16
9
  type: "action",
17
10
  props: {
18
- salesForceRestApi,
11
+ salesforce,
19
12
  campaignId: {
20
13
  propDefinition: [
21
- salesForceRestApi,
22
- "sobjectId",
14
+ salesforce,
15
+ "recordId",
23
16
  () => ({
24
- objectType: constants.OBJECT_TYPE.CAMPAIGN,
17
+ objType: "Campaign",
18
+ nameField: "Name",
25
19
  }),
26
20
  ],
27
21
  label: "Campaign ID",
28
- description: "ID of the Campaign to which this Lead is associated.",
22
+ description: "The Campaign to add a Lead to.",
29
23
  },
30
24
  leadId: {
31
25
  propDefinition: [
32
- salesForceRestApi,
33
- "sobjectId",
26
+ salesforce,
27
+ "recordId",
34
28
  () => ({
35
- objectType: constants.OBJECT_TYPE.LEAD,
29
+ objType: "Lead",
30
+ nameField: "Name",
36
31
  }),
37
32
  ],
38
33
  label: "Lead ID",
39
- description: "ID of the Lead who is associated with a Campaign.",
34
+ description: "The Lead to add to the selected Campaign.",
40
35
  },
41
36
  },
42
37
  async run({ $ }) {
43
- const data = removeNullEntries({
44
- CampaignId: this.campaignId,
45
- LeadId: this.leadId,
38
+ const {
39
+ salesforce, campaignId, leadId,
40
+ } = this;
41
+ const response = await salesforce.createObject({
42
+ $,
43
+ objectType: constants.OBJECT_TYPE.CAMPAIGN_MEMBER,
44
+ data: {
45
+ CampaignId: campaignId,
46
+ LeadId: leadId,
47
+ },
46
48
  });
47
- const response = await this.salesForceRestApi.createObject("CampaignMember", data);
48
- response && $.export("$summary", "Successfully added lead to campaign");
49
+ $.export("$summary", `Successfully added lead (ID: ${leadId}) to campaign (ID: ${campaignId})`);
49
50
  return response;
50
51
  },
51
52
  };
@@ -0,0 +1,108 @@
1
+ import { ConfigurationError } from "@pipedream/platform";
2
+ import salesforce from "../../salesforce_rest_api.app.mjs";
3
+ import { getAdditionalFields } from "../../common/props-utils.mjs";
4
+
5
+ export const additionalFields = {
6
+ type: "object",
7
+ label: "Additional Fields",
8
+ description:
9
+ "Other fields to set for this record. Values will be parsed as JSON where applicable.",
10
+ optional: true,
11
+ };
12
+
13
+ export function getProps({
14
+ objType,
15
+ createOrUpdate = "create",
16
+ docsLink = "https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_concepts.htm",
17
+ showDateInfo = false,
18
+ }) {
19
+ let { initialProps } = objType;
20
+ if (initialProps && createOrUpdate === "update") {
21
+ initialProps = Object.fromEntries(
22
+ Object.entries(initialProps).map(([
23
+ key,
24
+ value,
25
+ ]) => [
26
+ key,
27
+ {
28
+ ...value,
29
+ optional: true,
30
+ },
31
+ ]),
32
+ );
33
+ }
34
+
35
+ return {
36
+ salesforce,
37
+ ...showDateInfo && {
38
+ dateInfo: {
39
+ type: "alert",
40
+ alertType: "warning",
41
+ content: "Date fields should be a [valid date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format) or a Unix timestamp in milliseconds. Example values: `2022-01-15T18:30:00.000Z` or `1642271400000`.",
42
+ },
43
+ },
44
+ ...objType[createOrUpdate === "create"
45
+ ? "createProps"
46
+ : "updateProps"],
47
+ ...initialProps,
48
+ docsInfo: {
49
+ type: "alert",
50
+ alertType: "info",
51
+ content: `[See the documentation](${docsLink}) for more information on available fields.`,
52
+ },
53
+ useAdvancedProps: {
54
+ propDefinition: [
55
+ salesforce,
56
+ "useAdvancedProps",
57
+ ],
58
+ },
59
+ };
60
+ }
61
+
62
+ export default {
63
+ methods: {
64
+ getObjectType() {
65
+ return "";
66
+ },
67
+ getAdvancedProps() {
68
+ return {};
69
+ },
70
+ getAdditionalFields,
71
+ formatDateTimeProps(props = {}) {
72
+ // https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_valid_date_formats.htm
73
+ return Object.fromEntries(Object.entries(props).filter(([
74
+ , value,
75
+ ]) => value !== undefined)
76
+ .map(([
77
+ key,
78
+ value,
79
+ ]) => {
80
+ const numValue = Number(value);
81
+ const date = new Date(Number.isNaN(numValue)
82
+ ? value
83
+ : numValue);
84
+ if (Number.isNaN(date.valueOf())) {
85
+ throw new ConfigurationError(`Invalid date format for prop \`${key}\`. Please provide a valid date format.`);
86
+ }
87
+ return [
88
+ key,
89
+ date.toISOString(),
90
+ ];
91
+ }));
92
+ },
93
+ },
94
+ async additionalProps() {
95
+ const objectType = this.getObjectType();
96
+ if (!this.useAdvancedProps || !objectType) return {};
97
+
98
+ const fields = (await this.salesforce.getFieldsForObjectType(objectType));
99
+ const fieldNames = fields.map((f) => f.name);
100
+ const filteredProps = Object.fromEntries(Object.entries(this.getAdvancedProps()).filter(([
101
+ key,
102
+ ]) => fieldNames.includes(key) || key[0] === key[0].toLowerCase()));
103
+ return {
104
+ ...filteredProps,
105
+ additionalFields,
106
+ };
107
+ },
108
+ };
@@ -5,10 +5,17 @@ export default {
5
5
  key: "salesforce_rest_api-convert-soap-xml-to-json",
6
6
  name: "Convert SOAP XML Object to JSON",
7
7
  description: "Converts a SOAP XML Object received from Salesforce to JSON",
8
- version: "0.0.5",
8
+ version: "0.0.6",
9
9
  type: "action",
10
10
  props: {
11
11
  salesforce_rest_api,
12
+ infoBox: {
13
+ type: "alert",
14
+ alertType: "info",
15
+ content: `This action is useful in conjunction with Salesforce Flow Builder, and is primarily used if Instant triggers are not working for your use case.
16
+ \\
17
+ [See the documentation](https://pipedream.com/apps/salesforce-rest-api#troubleshooting) for more details.`,
18
+ },
12
19
  xml: {
13
20
  type: "string",
14
21
  label: "XML Soap Object",
@@ -17,14 +24,14 @@ export default {
17
24
  extractNotificationOnly: {
18
25
  type: "boolean",
19
26
  label: "Extract Notifications Only",
20
- description: "Extracts only the notification parts from the XML. Default: `true`.",
27
+ description: "Whether to extract only the notification parts from the XML. Default: `true`.",
21
28
  optional: true,
22
29
  default: true,
23
30
  },
24
31
  failOnError: {
25
32
  type: "boolean",
26
33
  label: "Fail on Error",
27
- description: "If should fail on error when extracting notifications. Default: `false`.",
34
+ description: "Whether the action should fail if an error occurs when extracting notifications. Default: `false`.",
28
35
  optional: true,
29
36
  default: false,
30
37
  },
@@ -44,6 +51,7 @@ export default {
44
51
  try {
45
52
  const notifications = json.elements[0].elements[0].elements[0].elements
46
53
  .filter(({ name }) => name === "Notification");
54
+ $.export("$summary", "Successfully converted to JSON and extracted notifications");
47
55
  return {
48
56
  notifications,
49
57
  };
@@ -1,52 +1,49 @@
1
- import common from "../common/base.mjs";
1
+ import common, { getProps } from "../common/base-create-update.mjs";
2
2
  import account from "../../common/sobjects/account.mjs";
3
- import {
4
- pickBy, pick,
5
- } from "lodash-es";
6
- import { toSingleLineString } from "../../common/utils.mjs";
7
3
 
8
- const { salesforce } = common.props;
4
+ export const docsLink = "https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_account.htm";
9
5
 
10
6
  export default {
11
7
  ...common,
12
8
  key: "salesforce_rest_api-create-account",
13
9
  name: "Create Account",
14
- description: toSingleLineString(`
15
- Creates a Salesforce account, representing an individual account,
16
- which is an organization or person involved with your business (such as customers, competitors, and partners).
17
- See [Account SObject](https://developer.salesforce.com/docs/atlas.en-us.228.0.object_reference.meta/object_reference/sforce_api_objects_account.htm)
18
- and [Create Record](https://developer.salesforce.com/docs/atlas.en-us.228.0.api_rest.meta/api_rest/dome_sobject_create.htm)
19
- `),
20
- version: "0.2.7",
10
+ description: `Creates a Salesforce account. [See the documentation](${docsLink})`,
11
+ version: "0.3.0",
21
12
  type: "action",
22
- props: {
23
- salesforce,
24
- Name: {
25
- type: "string",
26
- label: "Name",
27
- description: "Name of the account.",
13
+ methods: {
14
+ ...common.methods,
15
+ getObjectType() {
16
+ return "Account";
28
17
  },
29
- selector: {
30
- propDefinition: [
31
- salesforce,
32
- "fieldSelector",
33
- ],
34
- description: `${salesforce.propDefinitions.fieldSelector.description} Account`,
35
- options: () => Object.keys(account),
36
- reloadProps: true,
18
+ getAdvancedProps() {
19
+ return account.extraProps;
37
20
  },
38
21
  },
39
- additionalProps() {
40
- return this.additionalProps(this.selector, account);
41
- },
22
+ props: getProps({
23
+ objType: account,
24
+ docsLink,
25
+ }),
42
26
  async run({ $ }) {
43
- const data = pickBy(pick(this, [
44
- "Name",
45
- ...this.selector,
46
- ]));
47
- const response = await this.salesforce.createAccount({
27
+ /* eslint-disable no-unused-vars */
28
+ const {
29
+ salesforce,
30
+ getAdvancedProps,
31
+ getObjectType,
32
+ getAdditionalFields,
33
+ formatDateTimeProps,
34
+ useAdvancedProps,
35
+ docsInfo,
36
+ dateInfo,
37
+ additionalFields,
38
+ ...data
39
+ } = this;
40
+ /* eslint-enable no-unused-vars */
41
+ const response = await salesforce.createRecord("Account", {
48
42
  $,
49
- data,
43
+ data: {
44
+ ...data,
45
+ ...getAdditionalFields(),
46
+ },
50
47
  });
51
48
  $.export("$summary", `Successfully created account "${this.Name}"`);
52
49
  return response;
@@ -1,63 +1,49 @@
1
- import common from "../common/base.mjs";
1
+ import common, { getProps } from "../common/base-create-update.mjs";
2
2
  import attachment from "../../common/sobjects/attachment.mjs";
3
- import {
4
- pickBy, pick,
5
- } from "lodash-es";
6
- import { toSingleLineString } from "../../common/utils.mjs";
3
+ import fs from "fs";
7
4
 
8
- const { salesforce } = common.props;
5
+ const docsLink = "https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_attachment.htm";
6
+
7
+ /* eslint-disable no-unused-vars */
8
+ const {
9
+ useAdvancedProps, ...props
10
+ } = getProps({
11
+ objType: attachment,
12
+ docsLink,
13
+ });
14
+ /* eslint-enable no-unused-vars */
9
15
 
10
16
  export default {
11
17
  ...common,
12
18
  key: "salesforce_rest_api-create-attachment",
13
19
  name: "Create Attachment",
14
- description: toSingleLineString(`
15
- Creates an attachment, which represents a file that a User has uploaded and attached to a parent object.
16
- See [Attachment SObject](https://developer.salesforce.com/docs/atlas.en-us.228.0.object_reference.meta/object_reference/sforce_api_objects_attachment.htm)
17
- and [Create Record](https://developer.salesforce.com/docs/atlas.en-us.228.0.api_rest.meta/api_rest/dome_sobject_create.htm)
18
- `),
19
- version: "0.3.7",
20
+ description: `Creates an Attachment on a parent object. [See the documentation](${docsLink})`,
21
+ version: "0.4.0",
20
22
  type: "action",
21
- props: {
22
- salesforce,
23
- Body: {
24
- type: "string",
25
- label: "Body",
26
- description: "Encoded file data.",
27
- },
28
- Name: {
29
- type: "string",
30
- label: "Name",
31
- description: "Name of the attached file. Maximum size is 255 characters.",
32
- },
33
- ParentId: {
34
- type: "string",
35
- label: "Parent ID",
36
- description: "ID of the parent object of the attachment. The following objects are supported as parents of attachments:\n* Account\n* Asset\n* Campaign\n* Case\n* Contact\n* Contract\n* Custom objects\n* EmailMessage\n* EmailTemplate\n* Event\n* Lead\n* Opportunity\n* Product2\n* Solution\n* Task",
37
- },
38
- selector: {
39
- propDefinition: [
40
- salesforce,
41
- "fieldSelector",
42
- ],
43
- description: `${salesforce.propDefinitions.fieldSelector.description} Attachment`,
44
- options: () => Object.keys(attachment),
45
- reloadProps: true,
46
- },
47
- },
48
- additionalProps() {
49
- return this.additionalProps(this.selector, attachment);
50
- },
23
+ props,
51
24
  async run({ $ }) {
52
- const data = pickBy(pick(this, [
53
- "Body",
54
- "Name",
55
- "ParentId",
56
- ...this.selector,
57
- ]));
58
- const response = await this.salesforce.createAttachment({
25
+ /* eslint-disable no-unused-vars */
26
+ const {
27
+ salesforce,
28
+ getAdvancedProps,
29
+ getAdditionalFields,
30
+ formatDateTimeProps,
31
+ docsInfo,
32
+ filePathOrContent,
33
+ ...data
34
+ } = this;
35
+ /* eslint-enable no-unused-vars */
36
+
37
+ const body = filePathOrContent.includes("tmp/")
38
+ ? (await fs.promises.readFile(filePathOrContent)).toString("base64")
39
+ : filePathOrContent;
40
+
41
+ const response = await salesforce.createRecord("Attachment", {
59
42
  $,
60
- data,
43
+ data: {
44
+ Body: body,
45
+ ...data,
46
+ },
61
47
  });
62
48
  $.export("$summary", `Successfully created attachment "${this.Name}"`);
63
49
  return response;