Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wr/hard delete #959

Merged
merged 6 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"async",
"file",
"flags-dir",
"hard-delete",
"json",
"loglevel",
"sobject",
Expand Down
4 changes: 4 additions & 0 deletions messages/bulk.operation.command.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ Run the command asynchronously.
# flags.verbose.summary

Print verbose output of failed records if result is available.

# hard-delete-permission-error

You must have the "Bulk API Hard Delete" system permission to use the --hard-delete flag. This permission is disabled by default and can be enabled only by a system administrator.
10 changes: 9 additions & 1 deletion messages/bulkv2.delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ When you execute this command, it starts a job, displays the ID, and then immedi

- Bulk delete records from a custom object in an org with alias my-scratch and wait 5 minutes for the command to complete:

<%= config.bin %> <%= command.id %> --sobject MyObject__c --file files/delete.csv --wait 5 --target-org my-scratch
<%= config.bin %> <%= command.id %> --sobject MyObject\_\_c --file files/delete.csv --wait 5 --target-org my-scratch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<%= config.bin %> <%= command.id %> --sobject MyObject\_\_c --file files/delete.csv --wait 5 --target-org my-scratch
<%= config.bin %> <%= command.id %> --sobject MyObject__c --file files/delete.csv --wait 5 --target-org my-scratch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WillieRuemmele , please ensure that this doesn't get changed again -- there's something in an IDE that automatically switches "__c" to "\_\_c" so we need to be vigilant :)


# flags.hard-delete.summary

summary for Juliet here :)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
summary for Juliet here :)
Mark the records as immediately eligible for deletion by your org. If you don't specify this flag, the deleted records go into the Recycle Bin.


# flags.hard-delete.description

description here :)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description here :)
You must have the "Bulk API Hard Delete" system permission to use this flag. The permission is disabled by default and can be enabled only by a system administrator.

12 changes: 7 additions & 5 deletions src/BulkBaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

import { SfCommand, Spinner } from '@salesforce/sf-plugins-core';
import { IngestJobV2, JobInfoV2 } from '@jsforce/jsforce-node/lib/api/bulk2.js';
import type { IngestJobV2, JobInfoV2 } from '@jsforce/jsforce-node/lib/api/bulk2.js';
import { Duration } from '@salesforce/kit';
import { capitalCase } from 'change-case';
import { Messages } from '@salesforce/core';
import { Schema } from '@jsforce/jsforce-node';
import type { Schema } from '@jsforce/jsforce-node';
import { getResultMessage } from './reporters/reporters.js';
import { BulkDataRequestCache } from './bulkDataRequestCache.js';

Expand Down Expand Up @@ -70,9 +70,11 @@ export const displayBulkV2Result = ({
cmd: SfCommand<unknown>;
username?: string;
}): void => {
// if we just read from jobInfo.operation it may suggest running the nonexistent `sf data hardDelete resume` command
const operation = jobInfo.operation === 'hardDelete' || jobInfo.operation === 'delete' ? 'delete' : jobInfo.operation;
if (isAsync && jobInfo.state !== 'JobComplete' && jobInfo.state !== 'Failed') {
cmd.logSuccess(messages.getMessage('success', [jobInfo.operation, jobInfo.id]));
cmd.info(messages.getMessage('checkStatus', [jobInfo.operation, jobInfo.id, username]));
cmd.logSuccess(messages.getMessage('success', [operation, jobInfo.id]));
cmd.info(messages.getMessage('checkStatus', [operation, jobInfo.id, username]));
} else {
cmd.log();
cmd.info(getResultMessage(jobInfo));
Expand All @@ -81,7 +83,7 @@ export const displayBulkV2Result = ({
process.exitCode = 1;
}
if (jobInfo.state === 'InProgress' || jobInfo.state === 'Open') {
cmd.info(messages.getMessage('checkStatus', [jobInfo.operation, jobInfo.id, username]));
cmd.info(messages.getMessage('checkStatus', [operation, jobInfo.id, username]));
}
if (jobInfo.state === 'Failed') {
throw messages.createError('bulkJobFailed', [jobInfo.id]).setData(jobInfo);
Expand Down
2 changes: 1 addition & 1 deletion src/api/data/tree/exportApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import path from 'node:path';
import fs from 'node:fs';

import { Logger, Messages, Org, SfError, Lifecycle } from '@salesforce/core';
import { DescribeSObjectResult, QueryResult } from '@jsforce/jsforce-node';
import type { DescribeSObjectResult, QueryResult } from '@jsforce/jsforce-node';
import { Ux } from '@salesforce/sf-plugins-core';
import {
BasicRecord,
Expand Down
2 changes: 1 addition & 1 deletion src/api/file/fileToContentVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { readFile } from 'node:fs/promises';
import { basename } from 'node:path';
import { Connection } from '@salesforce/core';
import { Record, SaveResult } from '@jsforce/jsforce-node';
import type { Record, SaveResult } from '@jsforce/jsforce-node';
import FormData from 'form-data';

export type ContentVersion = {
Expand Down
4 changes: 2 additions & 2 deletions src/batcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import { ReadStream } from 'node:fs';
import { Connection, Messages, SfError } from '@salesforce/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { Schema } from '@jsforce/jsforce-node';
import type { Schema } from '@jsforce/jsforce-node';
import { stringify } from 'csv-stringify/sync';
import { parse } from 'csv-parse';
import {
import type {
Batch,
BatchInfo,
BulkIngestBatchResult,
Expand Down
13 changes: 8 additions & 5 deletions src/bulkOperationCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
import fs from 'node:fs';
import { ReadStream } from 'node:fs';
import os from 'node:os';

import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { Duration } from '@salesforce/kit';
import { Connection, Messages } from '@salesforce/core';
import { Ux } from '@salesforce/sf-plugins-core/Ux';
import { Schema } from '@jsforce/jsforce-node';
import type { Schema } from '@jsforce/jsforce-node';
import {
BulkV2,
IngestJobV2,
Expand Down Expand Up @@ -77,7 +76,7 @@ export const baseFlags = {
}),
};

type SupportedOperations = Extract<IngestOperation, 'delete' | 'upsert'>;
type SupportedOperations = Extract<IngestOperation, 'hardDelete' | 'delete' | 'upsert'>;

export const runBulkOperation = async ({
sobject,
Expand Down Expand Up @@ -147,6 +146,10 @@ export const runBulkOperation = async ({
}
return result;
} catch (err) {
if (err instanceof Error && err.name === 'FEATURENOTENABLED' && operation === 'hardDelete') {
// add info specific to hardDelete permission
err.message = messages.getMessage('hard-delete-permission-error');
}
cmd.spinner.stop();
throw err;
}
Expand All @@ -156,6 +159,7 @@ export const runBulkOperation = async ({
};
const getCache = async (operation: SupportedOperations): Promise<BulkDataRequestCache> => {
switch (operation) {
case 'hardDelete':
case 'delete':
return BulkDeleteRequestCache.create();
case 'upsert':
Expand All @@ -168,8 +172,7 @@ const getCache = async (operation: SupportedOperations): Promise<BulkDataRequest
*
* @param job {IngestJobV2}
* @param input
* @param sobjectType {string}
* @param wait {number}
* @param endWaitTime
*/
const executeBulkV2DataRequest = async <J extends Schema>(
job: IngestJobV2<J>,
Expand Down
2 changes: 1 addition & 1 deletion src/bulkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
IngestJobV2UnprocessedRecords,
} from '@jsforce/jsforce-node/lib/api/bulk2.js';

import { Schema } from '@jsforce/jsforce-node';
import type { Schema } from '@jsforce/jsforce-node';
import { Connection, Messages } from '@salesforce/core';
import { BulkProcessedRecordV2, BulkRecordsV2 } from './types.js';

Expand Down
2 changes: 1 addition & 1 deletion src/commands/data/create/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Messages } from '@salesforce/core';
import { SaveResult } from '@jsforce/jsforce-node';
import type { SaveResult } from '@jsforce/jsforce-node';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { orgFlags, perflogFlag } from '../../../flags.js';
import { stringToDictionary, collectErrorMessages } from '../../../dataCommand.js';
Expand Down
13 changes: 10 additions & 3 deletions src/commands/data/delete/bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Messages } from '@salesforce/core';
import { Duration } from '@salesforce/kit';
import { SfCommand } from '@salesforce/sf-plugins-core';
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { baseFlags, runBulkOperation } from '../../../bulkOperationCommand.js';
import { BulkResultV2 } from '../../../types.js';

Expand All @@ -19,7 +19,14 @@ export default class Delete extends SfCommand<BulkResultV2> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');

public static readonly flags = baseFlags;
public static readonly flags = {
...baseFlags,
'hard-delete': Flags.boolean({
summary: messages.getMessage('flags.hard-delete.summary'),
description: messages.getMessage('flags.hard-delete.description'),
default: false,
}),
};

public async run(): Promise<BulkResultV2> {
const { flags } = await this.parse(Delete);
Expand All @@ -30,7 +37,7 @@ export default class Delete extends SfCommand<BulkResultV2> {
connection: flags['target-org'].getConnection(flags['api-version']),
wait: flags.async ? Duration.minutes(0) : flags.wait,
verbose: flags.verbose,
operation: 'delete',
operation: flags['hard-delete'] ? 'hardDelete' : 'delete',
});
}
}
2 changes: 1 addition & 1 deletion src/commands/data/delete/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Messages, SfError } from '@salesforce/core';
import { SaveResult } from '@jsforce/jsforce-node';
import type { SaveResult } from '@jsforce/jsforce-node';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { orgFlags, perflogFlag } from '../../../flags.js';
import { collectErrorMessages, query } from '../../../dataCommand.js';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/data/get/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Messages, SfError } from '@salesforce/core';
import { Record } from '@jsforce/jsforce-node';
import type { Record } from '@jsforce/jsforce-node';
import { toAnyJson } from '@salesforce/ts-types';
import { SfCommand, Flags, Ux } from '@salesforce/sf-plugins-core';
import { orgFlags, perflogFlag } from '../../../flags.js';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/data/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import fs from 'node:fs';

import { Connection, Logger, Messages, SfError } from '@salesforce/core';
import { Record as jsforceRecord } from '@jsforce/jsforce-node';
import type { Record as jsforceRecord } from '@jsforce/jsforce-node';
import {
AnyJson,
ensureJsonArray,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/data/query/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Messages } from '@salesforce/core';
import { QueryJobV2 } from '@jsforce/jsforce-node/lib/api/bulk2.js';
import { Record as jsforceRecord } from '@jsforce/jsforce-node';
import type { Record as jsforceRecord } from '@jsforce/jsforce-node';
import {
Flags,
loglevel,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/data/update/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Messages, SfError } from '@salesforce/core';
import { SaveError, SaveResult } from '@jsforce/jsforce-node';
import type { SaveError, SaveResult } from '@jsforce/jsforce-node';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { orgFlags } from '../../../flags.js';
import { collectErrorMessages, query, stringToDictionary } from '../../../dataCommand.js';
Expand Down
2 changes: 1 addition & 1 deletion src/dataCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Connection, Messages, SfError } from '@salesforce/core';
import { Record as jsforceRecord, SaveResult } from '@jsforce/jsforce-node';
import type { Record as jsforceRecord, SaveResult } from '@jsforce/jsforce-node';

import { Ux } from '@salesforce/sf-plugins-core';
import { GenericObject } from './types.js';
Expand Down
2 changes: 1 addition & 1 deletion src/dataSoqlQueryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { QueryResult, Record } from '@jsforce/jsforce-node';
import type { QueryResult, Record } from '@jsforce/jsforce-node';
import { Optional } from '@salesforce/ts-types';
import { GenericEntry } from './types.js';

Expand Down
2 changes: 1 addition & 1 deletion src/queryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { Record } from '@jsforce/jsforce-node';
import type { Record } from '@jsforce/jsforce-node';
import { Field, FieldType, SoqlQueryResult } from './dataSoqlQueryTypes.js';
import { FormatTypes, JsonReporter } from './reporters/reporters.js';
import { CsvReporter } from './reporters/csvReporter.js';
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/csvReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { EOL } from 'node:os';
import { Ux } from '@salesforce/sf-plugins-core';
import { get, getNumber, isString } from '@salesforce/ts-types';
import { Record as jsforceRecord } from '@jsforce/jsforce-node';
import type { Record as jsforceRecord } from '@jsforce/jsforce-node';
import { Field, SoqlQueryResult } from '../dataSoqlQueryTypes.js';
import { getAggregateAliasOrName, maybeMassageAggregates } from './reporters.js';
import { QueryReporter, logFields, isSubquery, isAggregate } from './reporters.js';
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/humanReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Ux } from '@salesforce/sf-plugins-core';
import ansis from 'ansis';
import { get, getArray, isPlainObject, isString, Optional } from '@salesforce/ts-types';
import { Messages } from '@salesforce/core';
import { Record as jsforceRecord } from '@jsforce/jsforce-node';
import type { Record as jsforceRecord } from '@jsforce/jsforce-node';
import { GenericEntry, GenericObject } from '../types.js';
import { Field, FieldType, SoqlQueryResult } from '../dataSoqlQueryTypes.js';
import { QueryReporter, logFields, isSubquery, isAggregate, getAggregateAliasOrName } from './reporters.js';
Expand Down
2 changes: 1 addition & 1 deletion test/api/data/tree/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { expect, config } from 'chai';
import { DescribeSObjectResult } from '@jsforce/jsforce-node';
import type { DescribeSObjectResult } from '@jsforce/jsforce-node';
import {
RefFromIdByType,
buildRefMap,
Expand Down
2 changes: 1 addition & 1 deletion test/commands/data/create/file.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'node:fs';
import path from 'node:path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { expect } from 'chai';
import { SaveResult } from '@jsforce/jsforce-node';
import type { SaveResult } from '@jsforce/jsforce-node';
import { SoqlQueryResult } from '../../../../src/dataSoqlQueryTypes.js';
import { ContentVersion } from '../../../../src/api/file/fileToContentVersion.js';

Expand Down
2 changes: 1 addition & 1 deletion test/commands/data/create/record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Config } from '@oclif/core/config';
import { expect } from 'chai';
import { TestContext, MockTestOrgData } from '@salesforce/core/testSetup';
import { AnyJson, ensureJsonMap, ensureString } from '@salesforce/ts-types';
import { SaveResult } from '@jsforce/jsforce-node';
import type { SaveResult } from '@jsforce/jsforce-node';
import Create from '../../../../src/commands/data/create/record.js';
const sObjectId = '0011100001zhhyUAAQ';

Expand Down
2 changes: 1 addition & 1 deletion test/commands/data/dataBulk.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { expect, config as chaiConfig } from 'chai';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { sleep } from '@salesforce/kit';
import { ensurePlainObject } from '@salesforce/ts-types';
import { SaveResult } from '@jsforce/jsforce-node';
import type { SaveResult } from '@jsforce/jsforce-node';
import { BulkResultV2 } from '../../../src/types.js';
import { QueryResult } from './dataSoqlQuery.nut.js';

Expand Down
Loading