Skip to content

Commit 97a2b77

Browse files
committed
[ACTION] Salesforce Accounts/Opportunities Batch Create/UpdateDD
1 parent 1b4d96e commit 97a2b77

File tree

8 files changed

+210
-3
lines changed

8 files changed

+210
-3
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import {
2+
ConfigurationError,
3+
getFileStream,
4+
} from "@pipedream/platform";
5+
import app from "../../salesforce_rest_api.app.mjs";
6+
7+
export default {
8+
props: {
9+
app,
10+
csvFilePath: {
11+
type: "string",
12+
label: "CSV File Path Or URL",
13+
description: "The path to the CSV file to process. Provide a path to a file in the `/tmp` directory (for example, `/tmp/data.csv`). If a URL is provided, the file will be downloaded to the `/tmp` directory. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_prepare_data.htm)",
14+
},
15+
},
16+
methods: {
17+
getObject() {
18+
throw new ConfigurationError("getObject method not implemented");
19+
},
20+
getOperation() {
21+
throw new ConfigurationError("getOperation method not implemented");
22+
},
23+
getSummary() {
24+
throw new ConfigurationError("getSummary method not implemented");
25+
},
26+
async processBulkOperation({
27+
object, operation, csvData, externalIdFieldName, ...args
28+
} = {}) {
29+
const { app } = this;
30+
const job = await app.createBulkJob({
31+
...args,
32+
data: {
33+
object,
34+
operation,
35+
externalIdFieldName,
36+
},
37+
});
38+
39+
await app.uploadBulkJobData({
40+
...args,
41+
jobId: job.id,
42+
data: csvData,
43+
});
44+
45+
await app.patchBulkJob({
46+
...args,
47+
jobId: job.id,
48+
data: {
49+
state: "UploadComplete",
50+
},
51+
});
52+
53+
return app.getBulkJobInfo({
54+
...args,
55+
jobId: job.id,
56+
});
57+
},
58+
},
59+
async run({ $ }) {
60+
const {
61+
processBulkOperation,
62+
getObject,
63+
getOperation,
64+
getSummary,
65+
csvFilePath,
66+
} = this;
67+
68+
const csvData = await getFileStream(csvFilePath);
69+
70+
const result = await processBulkOperation({
71+
$,
72+
object: getObject(),
73+
operation: getOperation(),
74+
csvData,
75+
});
76+
77+
$.export("$summary", getSummary());
78+
79+
return result;
80+
},
81+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import common from "../common/batch-operation.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesforce_rest_api-create-accounts-batch",
6+
name: "Create Accounts (Batch)",
7+
description: "Create multiple Accounts in Salesforce using Bulk API 2.0. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_understanding_bulk2_ingest.htm)",
8+
version: "0.0.1",
9+
type: "action",
10+
methods: {
11+
getObject() {
12+
return "Account";
13+
},
14+
getOperation() {
15+
return "insert";
16+
},
17+
getSummary() {
18+
return "Successfully created Accounts";
19+
},
20+
},
21+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import common from "../common/batch-operation.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesforce_rest_api-create-opportunities-batch",
6+
name: "Create Opportunities (Batch)",
7+
description: "Create multiple Opportunities in Salesforce using Bulk API 2.0. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_understanding_bulk2_ingest.htm)",
8+
version: "0.0.1",
9+
type: "action",
10+
methods: {
11+
getObject() {
12+
return "Opportunity";
13+
},
14+
getOperation() {
15+
return "insert";
16+
},
17+
getSummary() {
18+
return "Successfully created Opportunities";
19+
},
20+
},
21+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import common from "../common/batch-operation.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesforce_rest_api-update-accounts-batch",
6+
name: "Update Accounts (Batch)",
7+
description: "Update multiple Accounts in Salesforce using Bulk API 2.0. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_understanding_bulk2_ingest.htm)",
8+
version: "0.0.1",
9+
type: "action",
10+
methods: {
11+
getObject() {
12+
return "Account";
13+
},
14+
getOperation() {
15+
return "update";
16+
},
17+
getSummary() {
18+
return "Successfully updated Accounts";
19+
},
20+
},
21+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import common from "../common/batch-operation.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesforce_rest_api-update-opportunities-batch",
6+
name: "Update Opportunities (Batch)",
7+
description: "Update multiple Opportunities in Salesforce using Bulk API 2.0. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_understanding_bulk2_ingest.htm)",
8+
version: "0.0.1",
9+
type: "action",
10+
methods: {
11+
getObject() {
12+
return "Opportunity";
13+
},
14+
getOperation() {
15+
return "update";
16+
},
17+
getSummary() {
18+
return "Successfully updated Opportunities";
19+
},
20+
},
21+
};

components/salesforce_rest_api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/salesforce_rest_api",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"description": "Pipedream Salesforce (REST API) Components",
55
"main": "salesforce_rest_api.app.mjs",
66
"keywords": [

components/salesforce_rest_api/salesforce_rest_api.app.mjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,5 +366,48 @@ export default {
366366
...args,
367367
});
368368
},
369+
createBulkJob(args = {}) {
370+
return this._makeRequest({
371+
...args,
372+
method: "POST",
373+
url: `${this._baseApiVersionUrl()}/jobs/ingest`,
374+
data: {
375+
contentType: "CSV",
376+
columnDelimiter: "COMMA",
377+
lineEnding: "LF",
378+
...args?.data,
379+
},
380+
});
381+
},
382+
uploadBulkJobData({
383+
jobId, ...args
384+
} = {}) {
385+
return this._makeRequest({
386+
...args,
387+
method: "PUT",
388+
url: `${this._baseApiVersionUrl()}/jobs/ingest/${jobId}/batches`,
389+
headers: {
390+
...this._makeRequestHeaders(),
391+
"Content-Type": "text/csv",
392+
},
393+
});
394+
},
395+
patchBulkJob({
396+
jobId, ...args
397+
} = {}) {
398+
return this._makeRequest({
399+
...args,
400+
method: "PATCH",
401+
url: `${this._baseApiVersionUrl()}/jobs/ingest/${jobId}`,
402+
});
403+
},
404+
getBulkJobInfo({
405+
jobId, ...args
406+
} = {}) {
407+
return this._makeRequest({
408+
...args,
409+
url: `${this._baseApiVersionUrl()}/jobs/ingest/${jobId}`,
410+
});
411+
},
369412
},
370413
};

pnpm-lock.yaml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)