Skip to content

Commit

Permalink
Merge pull request #89 from w-andre/master
Browse files Browse the repository at this point in the history
support upserting more than 10 records
  • Loading branch information
FabienTaillon authored Jan 10, 2022
2 parents 2d923d0 + 4b9b2c8 commit caac8d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "texei-sfdx-plugin",
"description": "Texeï's plugin for sfdx",
"version": "1.14.0",
"version": "1.14.1",
"author": "Texeï",
"bugs": "https://github.com/https://github.com/texei/texei-sfdx-plugin/issues",
"dependencies": {
Expand Down
18 changes: 13 additions & 5 deletions src/commands/texei/data/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,19 @@ export default class Import extends SfdxCommand {
// external id field is specified --> upsert
this.debug(`DEBUG upserting ${sobjectName} records using external id field '${externalIdField}'`);

// @ts-ignore: Don't know why, but TypeScript doesn't use the correct method override
sobjectsResult = await conn.sobject(sobjectName).upsert(records, externalIdField, { allowRecursive: true, allOrNone: this.flags.allornone })
.catch(err => {
throw new SfdxError(`Error upserting records: ${err}`);
});
// max. parallel upsert requests as supported by jsforce (default)
// https://github.com/jsforce/jsforce/blob/82fcc5284215e95047d0f735dd3037a1aeba5d88/lib/connection.js#L82
const maxParallelUpsertRequests = 10;

for (var i = 0; i < records.length; i += maxParallelUpsertRequests) {
// @ts-ignore: Don't know why, but TypeScript doesn't use the correct method override
const chunkResults: RecordResult[] = await conn.sobject(sobjectName)
.upsert(records.slice(i, i + maxParallelUpsertRequests), externalIdField, { allowRecursive: true, allOrNone: this.flags.allornone })
.catch((err) => {
throw new SfdxError(`Error upserting records: ${err}`);
});
sobjectsResult.push(...chunkResults);
}
}
else if (records[0] && records[0].Id) {
// There is an Id, so it's an update
Expand Down

0 comments on commit caac8d0

Please sign in to comment.