@simplysf/simply-sobject 1.2.1 → 1.3.1

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.
package/README.md CHANGED
@@ -22,6 +22,8 @@ This package is part of the [`@simplysf/simply`](https://github.com/SimplySF/sim
22
22
 
23
23
  - [`sf simply sobject backup`](#sf-simply-sobject-backup)
24
24
  - [`sf simply sobject deduplicate`](#sf-simply-sobject-deduplicate)
25
+ - [`sf simply sobject history export`](#sf-simply-sobject-history-export)
26
+ - [`sf simply sobject history query`](#sf-simply-sobject-history-query)
25
27
 
26
28
  ## `sf simply sobject backup`
27
29
 
@@ -62,7 +64,7 @@ FLAG DESCRIPTIONS
62
64
  The API name of the SObject to back up.
63
65
  ```
64
66
 
65
- _See code: [lib/commands/simply/sobject/backup.js](https://github.com/SimplySF/simply/blob/@simplysf/simply-sobject@1.1.1/packages/simply-sobject/lib/commands/simply/sobject/backup.js)_
67
+ _See code: [lib/commands/simply/sobject/backup.js](https://github.com/SimplySF/simply/blob/@simplysf/simply-sobject@1.2.1/packages/simply-sobject/lib/commands/simply/sobject/backup.js)_
66
68
 
67
69
  ## `sf simply sobject deduplicate`
68
70
 
@@ -115,5 +117,115 @@ FLAG DESCRIPTIONS
115
117
  The directory to write the generated CSV files to. Defaults to ./temp/<primaryObjectApiName>.
116
118
  ```
117
119
 
118
- _See code: [lib/commands/simply/sobject/deduplicate.js](https://github.com/SimplySF/simply/blob/@simplysf/simply-sobject@1.1.1/packages/simply-sobject/lib/commands/simply/sobject/deduplicate.js)_
120
+ _See code: [lib/commands/simply/sobject/deduplicate.js](https://github.com/SimplySF/simply/blob/@simplysf/simply-sobject@1.2.1/packages/simply-sobject/lib/commands/simply/sobject/deduplicate.js)_
121
+
122
+ ## `sf simply sobject history export`
123
+
124
+ Export field history for an SObject within a date range to a CSV file.
125
+
126
+ ```
127
+ USAGE
128
+ $ sf simply sobject history export -s <value> --start-date <value> --end-date <value> -o <value> [--json] [--flags-dir <value>]
129
+ [--api-version <value>] [-d <value>]
130
+
131
+ FLAGS
132
+ -d, --output-dir=<value> Output directory
133
+ -o, --target-org=<value> (required) Username or alias of the target org. Not required if the `target-org`
134
+ configuration variable is already set.
135
+ -s, --sobject=<value> (required) SObject API name
136
+ --api-version=<value> Override the api version used for api requests made by this command
137
+ --end-date=<value> (required) End date (YYYY-MM-DD)
138
+ --start-date=<value> (required) Start date (YYYY-MM-DD)
139
+
140
+ GLOBAL FLAGS
141
+ --flags-dir=<value> Import flag values from a directory.
142
+ --json Format output as json.
143
+
144
+ DESCRIPTION
145
+ Export field history for an SObject within a date range to a CSV file.
146
+
147
+ Queries the field history object for the given SObject (e.g. `AccountHistory`, `Custom_Object__History`, or
148
+ `OpportunityFieldHistory`) for changes created within the given date range, and writes the results to a timestamped
149
+ CSV file.
150
+
151
+ EXAMPLES
152
+ $ sf simply sobject history export --target-org myOrg --sobject Account --start-date 2026-01-01 --end-date 2026-01-31
153
+
154
+ $ sf simply sobject history export --target-org myOrg --sobject Custom_Object__c --start-date 2026-01-01 --end-date 2026-01-31 --output-dir exports
155
+
156
+ FLAG DESCRIPTIONS
157
+ -d, --output-dir=<value> Output directory
158
+
159
+ The directory to save the exported CSV file to. Defaults to the current directory.
160
+
161
+ -s, --sobject=<value> SObject API name
162
+
163
+ The API name of the SObject to export field history for (e.g. Account or Custom_Object__c).
164
+
165
+ --end-date=<value> End date (YYYY-MM-DD)
166
+
167
+ The end of the date range to export history for, inclusive.
168
+
169
+ --start-date=<value> Start date (YYYY-MM-DD)
170
+
171
+ The start of the date range to export history for, inclusive.
172
+ ```
173
+
174
+ _See code: [lib/commands/simply/sobject/history/export.js](https://github.com/SimplySF/simply/blob/@simplysf/simply-sobject@1.2.1/packages/simply-sobject/lib/commands/simply/sobject/history/export.js)_
175
+
176
+ ## `sf simply sobject history query`
177
+
178
+ Query the field history of an SObject, with optional filtering.
179
+
180
+ ```
181
+ USAGE
182
+ $ sf simply sobject history query --object <value> -o <value> [--json] [--flags-dir <value>] [--api-version <value>] [--filters
183
+ <value>] [-d <value>]
184
+
185
+ FLAGS
186
+ -d, --output-dir=<value> Output directory
187
+ -o, --target-org=<value> (required) Username or alias of the target org. Not required if the `target-org`
188
+ configuration variable is already set.
189
+ --api-version=<value> Override the api version used for api requests made by this command
190
+ --filters=<value> Path to a filter configuration file, or a raw JSON filter string
191
+ --object=<value> (required) SObject API name
192
+
193
+ GLOBAL FLAGS
194
+ --flags-dir=<value> Import flag values from a directory.
195
+ --json Format output as json.
196
+
197
+ DESCRIPTION
198
+ Query the field history of an SObject, with optional filtering.
199
+
200
+ Queries the field history object for the given SObject (e.g. `AccountHistory`, `Custom_Object__History`, or
201
+ `OpportunityFieldHistory`) and writes the results to a timestamped CSV file. An optional filter tree can be supplied
202
+ to narrow the results: conditions on Field, CreatedById, CreatedDate, or the parent lookup field are pushed into the
203
+ SOQL WHERE clause; conditions on any other field (e.g. OldValue or NewValue) are applied client-side after the query
204
+ runs.
205
+
206
+ EXAMPLES
207
+ $ sf simply sobject history query --target-org myOrg --object Account
208
+
209
+ $ sf simply sobject history query --target-org myOrg --object Custom_Object__c --filters config/history-filters.json
210
+
211
+ $ sf simply sobject history query --target-org myOrg --object Account --filters '{"logic":"AND","filters":[{"field":"Field","operator":"=","value":"Name"}]}'
212
+
213
+ FLAG DESCRIPTIONS
214
+ -d, --output-dir=<value> Output directory
215
+
216
+ The directory to save the query results CSV file to. Defaults to the current directory.
217
+
218
+ --filters=<value> Path to a filter configuration file, or a raw JSON filter string
219
+
220
+ A JSON object describing a tree of filter conditions: `{ "logic": "AND", "filters": [ { "field": "Field",
221
+ "operator": "=", "value": "Status__c" } ] }`. Each entry in `filters` is either a condition (`field`, `operator`,
222
+ `value`) or another nested group with its own `logic`/`filters`. Supported operators are =, !=, >, <, >=, <=, IN,
223
+ NOT IN, and LIKE (using `%` as a wildcard).
224
+
225
+ --object=<value> SObject API name
226
+
227
+ The API name of the SObject to query field history for (e.g. Account or Custom_Object__c).
228
+ ```
229
+
230
+ _See code: [lib/commands/simply/sobject/history/query.js](https://github.com/SimplySF/simply/blob/@simplysf/simply-sobject@1.2.1/packages/simply-sobject/lib/commands/simply/sobject/history/query.js)_
119
231
  <!-- commandsstop -->
@@ -33,8 +33,7 @@ async function deduplicateAssociatedObject(options) {
33
33
  const recordStream = queryRecords(connection, `SELECT Id,${fieldsToQuery.join(',')} FROM ${objectName}`);
34
34
  const modifiedFile = path.join(outputDir, `${objectName}_Modified.csv`);
35
35
  const writer = createCsvFileWriter(modifiedFile, ['Id', ...lookupFields]);
36
- for await (const record of recordStream) {
37
- const associatedRecord = record;
36
+ for await (const associatedRecord of recordStream) {
38
37
  const modifiedRecord = {};
39
38
  for (const lookupField of lookupFields) {
40
39
  if (!associatedRecord[lookupField]) {
@@ -43,7 +42,7 @@ async function deduplicateAssociatedObject(options) {
43
42
  let compositeKey = '';
44
43
  for (const compositeKeyField of primaryObjectCompositeKeyFields) {
45
44
  const objectKey = `${lookupField.replace('__c', '__r')}.${compositeKeyField}`;
46
- compositeKey += `${String(associatedRecord[objectKey] ?? '')}_`;
45
+ compositeKey += `${associatedRecord[objectKey] ?? ''}_`;
47
46
  }
48
47
  compositeKey = compositeKey.slice(0, -1);
49
48
  const uniqueRecordId = uniquePrimaryObjectMap.get(compositeKey);
@@ -117,14 +116,13 @@ export default class SObjectDeduplicate extends SfCommand {
117
116
  let totalRecords = 0;
118
117
  let duplicateCount = 0;
119
118
  const uniquePrimaryObjectMap = new Map();
120
- for await (const record of primaryRecordStream) {
119
+ for await (const primaryRecord of primaryRecordStream) {
121
120
  totalRecords++;
122
- const primaryRecord = record;
123
121
  let compositeKey = '';
124
122
  const nullCompositeKeyFields = [];
125
123
  for (const field of primaryObjectCompositeKeyFields) {
126
124
  const value = primaryRecord[field];
127
- compositeKey += `${String(value ?? '')}_`;
125
+ compositeKey += `${value ?? ''}_`;
128
126
  if (!value) {
129
127
  nullCompositeKeyFields.push(field);
130
128
  }
@@ -1 +1 @@
1
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AAW,EAAE,CAAC;oBAClC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACnC,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,gCAAgC,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxG,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;QAED,MAAM,MAAM,GAA6B;YACvC,oBAAoB;YACpB,YAAY;YACZ,cAAc;YACd,WAAW,EAAE,sBAAsB,CAAC,IAAI;YACxC,UAAU;YACV,UAAU;YACV,aAAa;SACd,CAAC;QAEF,IAAI,CAAC,KAAK,CAAC;YACT,IAAI,EAAE;gBACJ,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE;gBAC/D,EAAE,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;gBACpE,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;aAChE;YACD,OAAO,EAAE;gBACP,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACjC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;aAChC;SACF,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ export type SObjectHistoryExportResult = {
3
+ sobject: string;
4
+ historyObject: string;
5
+ recordCount: number;
6
+ path: string;
7
+ };
8
+ export default class SObjectHistoryExport extends SfCommand<SObjectHistoryExportResult> {
9
+ static readonly summary: string;
10
+ static readonly description: string;
11
+ static readonly examples: string[];
12
+ static readonly flags: {
13
+ 'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ sobject: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
15
+ 'start-date': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
16
+ 'end-date': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
17
+ 'output-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ 'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
19
+ 'flags-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
+ };
21
+ run(): Promise<SObjectHistoryExportResult>;
22
+ }
@@ -0,0 +1,123 @@
1
+ /*
2
+ * Copyright (c) 2026, Clay Chipps; Copyright (c) 2026 Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import fs from 'node:fs';
17
+ import path from 'node:path';
18
+ import { Messages } from '@salesforce/core';
19
+ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
20
+ import { queryRecords, writeRecordsToCsvFile } from '@simplysf/simply-core';
21
+ import { getHistoryObjectName, getParentIdField } from '../../../../common/fieldHistory.js';
22
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
23
+ const messages = Messages.loadMessages('@simplysf/simply-sobject', 'simply.sobject.history.export');
24
+ const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
25
+ const CSV_COLUMNS = [
26
+ 'HISTORY_ID',
27
+ 'PARENT_ID',
28
+ 'CREATED_DATE',
29
+ 'CREATED_BY_ID',
30
+ 'CREATED_BY_NAME',
31
+ 'FIELD_API_NAME',
32
+ 'OLD_VALUE',
33
+ 'NEW_VALUE',
34
+ ];
35
+ async function* mapHistoryRecords(records, parentIdField) {
36
+ for await (const record of records) {
37
+ yield {
38
+ HISTORY_ID: record.Id ?? '',
39
+ PARENT_ID: record[parentIdField] ?? '',
40
+ CREATED_DATE: record.CreatedDate ?? '',
41
+ CREATED_BY_ID: record.CreatedById ?? '',
42
+ CREATED_BY_NAME: record['CreatedBy.Name'] || 'Unknown',
43
+ FIELD_API_NAME: record.Field ?? '',
44
+ OLD_VALUE: record.OldValue ?? '',
45
+ NEW_VALUE: record.NewValue ?? '',
46
+ };
47
+ }
48
+ }
49
+ export default class SObjectHistoryExport extends SfCommand {
50
+ static summary = messages.getMessage('summary');
51
+ static description = messages.getMessage('description');
52
+ static examples = messages.getMessages('examples');
53
+ static flags = {
54
+ ...SfCommand.baseFlags,
55
+ 'api-version': Flags.orgApiVersion(),
56
+ sobject: Flags.string({
57
+ summary: messages.getMessage('flags.sobject.summary'),
58
+ description: messages.getMessage('flags.sobject.description'),
59
+ char: 's',
60
+ required: true,
61
+ }),
62
+ 'start-date': Flags.string({
63
+ summary: messages.getMessage('flags.start-date.summary'),
64
+ description: messages.getMessage('flags.start-date.description'),
65
+ required: true,
66
+ // eslint-disable-next-line @typescript-eslint/require-await
67
+ parse: async (input) => {
68
+ if (!DATE_PATTERN.test(input)) {
69
+ throw messages.createError('error.invalidDate', ['start-date', input]);
70
+ }
71
+ return input;
72
+ },
73
+ }),
74
+ 'end-date': Flags.string({
75
+ summary: messages.getMessage('flags.end-date.summary'),
76
+ description: messages.getMessage('flags.end-date.description'),
77
+ required: true,
78
+ // eslint-disable-next-line @typescript-eslint/require-await
79
+ parse: async (input) => {
80
+ if (!DATE_PATTERN.test(input)) {
81
+ throw messages.createError('error.invalidDate', ['end-date', input]);
82
+ }
83
+ return input;
84
+ },
85
+ }),
86
+ 'output-dir': Flags.directory({
87
+ summary: messages.getMessage('flags.output-dir.summary'),
88
+ description: messages.getMessage('flags.output-dir.description'),
89
+ char: 'd',
90
+ }),
91
+ 'target-org': Flags.requiredOrg(),
92
+ };
93
+ async run() {
94
+ const { flags } = await this.parse(SObjectHistoryExport);
95
+ const targetOrgConnection = flags['target-org']?.getConnection(flags['api-version']);
96
+ if (!targetOrgConnection) {
97
+ throw messages.createError('error.targetOrgConnectionFailed');
98
+ }
99
+ const sobject = flags.sobject;
100
+ const historyObject = getHistoryObjectName(sobject);
101
+ const parentIdField = getParentIdField(sobject);
102
+ const startDateTime = `${flags['start-date']}T00:00:00Z`;
103
+ const endDateTime = `${flags['end-date']}T23:59:59Z`;
104
+ const soql = `SELECT Id, ${parentIdField}, CreatedDate, CreatedById, CreatedBy.Name, Field, OldValue, NewValue ` +
105
+ `FROM ${historyObject} WHERE CreatedDate >= ${startDateTime} AND CreatedDate <= ${endDateTime} ORDER BY CreatedDate DESC`;
106
+ const outputDir = flags['output-dir'] ?? '.';
107
+ if (!fs.existsSync(outputDir)) {
108
+ fs.mkdirSync(outputDir, { recursive: true });
109
+ }
110
+ const outputPath = path.join(outputDir, `${historyObject}_${buildTimestamp()}.csv`);
111
+ this.spinner.start(messages.getMessage('info.exportingHistory', [historyObject]));
112
+ const { recordCount } = await writeRecordsToCsvFile(mapHistoryRecords(queryRecords(targetOrgConnection, soql), parentIdField), outputPath, CSV_COLUMNS);
113
+ this.spinner.stop();
114
+ this.info(messages.getMessage('info.complete', [recordCount, outputPath]));
115
+ return { sobject, historyObject, recordCount, path: outputPath };
116
+ }
117
+ }
118
+ function buildTimestamp() {
119
+ const now = new Date();
120
+ const pad = (n) => n.toString().padStart(2, '0');
121
+ return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}_${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
122
+ }
123
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../../../../../src/commands/simply/sobject/history/export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAE5F,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,0BAA0B,EAAE,+BAA+B,CAAC,CAAC;AAEpG,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAE3C,MAAM,WAAW,GAAG;IAClB,YAAY;IACZ,WAAW;IACX,cAAc;IACd,eAAe;IACf,iBAAiB;IACjB,gBAAgB;IAChB,WAAW;IACX,WAAW;CACZ,CAAC;AASF,KAAK,SAAS,CAAC,CAAC,iBAAiB,CAC/B,OAA+C,EAC/C,aAAqB;IAErB,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QACnC,MAAM;YACJ,UAAU,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE;YAC3B,SAAS,EAAE,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;YACtC,YAAY,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;YACtC,aAAa,EAAE,MAAM,CAAC,W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AAI,EAAE,CAAC;IACvB,MAAM,GAAG,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACjE,OAAO,GAAG,GAAG,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAG,GAAG,CACrG,GAAG,CAAC,UAAU,EAAE,CACjB,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ export type SObjectHistoryQueryResult = {
3
+ object: string;
4
+ historyObject: string;
5
+ totalQueried: number;
6
+ totalWritten: number;
7
+ path: string;
8
+ };
9
+ export default class SObjectHistoryQuery extends SfCommand<SObjectHistoryQueryResult> {
10
+ static readonly summary: string;
11
+ static readonly description: string;
12
+ static readonly examples: string[];
13
+ static readonly flags: {
14
+ 'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ object: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
16
+ filters: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ 'output-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ 'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
19
+ 'flags-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
+ };
21
+ run(): Promise<SObjectHistoryQueryResult>;
22
+ }
@@ -0,0 +1,121 @@
1
+ /*
2
+ * Copyright (c) 2026, Clay Chipps; Copyright (c) 2026 Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import fs from 'node:fs';
17
+ import path from 'node:path';
18
+ import { Messages } from '@salesforce/core';
19
+ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
20
+ import { queryRecords, writeRecordsToCsvFile } from '@simplysf/simply-core';
21
+ import { buildWhereClause, getHistoryObjectName, getParentIdField, recordMatchesClientFilters, } from '../../../../common/fieldHistory.js';
22
+ import { FilterConfigSchema } from '../../../../schemas/history/filterConfig.js';
23
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
24
+ const messages = Messages.loadMessages('@simplysf/simply-sobject', 'simply.sobject.history.query');
25
+ const CSV_COLUMNS = ['Id', 'ParentId', 'Field', 'OldValue', 'NewValue', 'CreatedById', 'CreatedDate'];
26
+ function parseFilterConfig(filterInput) {
27
+ const raw = filterInput.endsWith('.json') && fs.existsSync(filterInput) ? fs.readFileSync(filterInput, 'utf-8') : filterInput;
28
+ try {
29
+ return JSON.parse(raw);
30
+ }
31
+ catch (error) {
32
+ throw messages.createError('error.invalidFiltersJson', [error.message]);
33
+ }
34
+ }
35
+ async function* filterAndMapHistoryRecords(records, filterConfig, parentFieldName, soqlFilterableFields, onRecordQueried) {
36
+ for await (const record of records) {
37
+ onRecordQueried();
38
+ if (!recordMatchesClientFilters(record, filterConfig, parentFieldName, soqlFilterableFields)) {
39
+ continue;
40
+ }
41
+ yield {
42
+ Id: record.Id ?? '',
43
+ ParentId: record[parentFieldName] ?? '',
44
+ Field: record.Field ?? '',
45
+ OldValue: record.OldValue ?? '',
46
+ NewValue: record.NewValue ?? '',
47
+ CreatedById: record.CreatedById ?? '',
48
+ CreatedDate: record.CreatedDate ?? '',
49
+ };
50
+ }
51
+ }
52
+ export default class SObjectHistoryQuery extends SfCommand {
53
+ static summary = messages.getMessage('summary');
54
+ static description = messages.getMessage('description');
55
+ static examples = messages.getMessages('examples');
56
+ static flags = {
57
+ ...SfCommand.baseFlags,
58
+ 'api-version': Flags.orgApiVersion(),
59
+ object: Flags.string({
60
+ summary: messages.getMessage('flags.object.summary'),
61
+ description: messages.getMessage('flags.object.description'),
62
+ required: true,
63
+ }),
64
+ filters: Flags.string({
65
+ summary: messages.getMessage('flags.filters.summary'),
66
+ description: messages.getMessage('flags.filters.description'),
67
+ }),
68
+ 'output-dir': Flags.directory({
69
+ summary: messages.getMessage('flags.output-dir.summary'),
70
+ description: messages.getMessage('flags.output-dir.description'),
71
+ char: 'd',
72
+ }),
73
+ 'target-org': Flags.requiredOrg(),
74
+ };
75
+ async run() {
76
+ const { flags } = await this.parse(SObjectHistoryQuery);
77
+ const targetOrgConnection = flags['target-org']?.getConnection(flags['api-version']);
78
+ if (!targetOrgConnection) {
79
+ throw messages.createError('error.targetOrgConnectionFailed');
80
+ }
81
+ const object = flags.object;
82
+ const historyObject = getHistoryObjectName(object);
83
+ const parentFieldName = getParentIdField(object);
84
+ const soqlFilterableFields = new Set(['Field', 'CreatedById', 'CreatedDate', 'ParentId', parentFieldName]);
85
+ let filterConfig;
86
+ if (flags.filters) {
87
+ const rawFilterConfig = parseFilterConfig(flags.filters);
88
+ const parsed = FilterConfigSchema.safeParse(rawFilterConfig);
89
+ if (!parsed.success) {
90
+ throw messages.createError('error.invalidFilters', [parsed.error.message]);
91
+ }
92
+ filterConfig = parsed.data;
93
+ }
94
+ let soql = `SELECT CreatedById, CreatedDate, Field, Id, NewValue, OldValue, ${parentFieldName} FROM ${historyObject}`;
95
+ const whereClause = buildWhereClause(filterConfig, parentFieldName, soqlFilterableFields);
96
+ if (whereClause) {
97
+ soql += ` WHERE ${whereClause}`;
98
+ }
99
+ soql += ' ORDER BY CreatedDate DESC';
100
+ this.info(messages.getMessage('info.generatedSoql', [soql]));
101
+ const outputDir = flags['output-dir'] ?? '.';
102
+ if (!fs.existsSync(outputDir)) {
103
+ fs.mkdirSync(outputDir, { recursive: true });
104
+ }
105
+ const outputPath = path.join(outputDir, `${historyObject}_${buildTimestamp()}.csv`);
106
+ this.spinner.start(messages.getMessage('info.queryingHistory', [historyObject]));
107
+ let totalQueried = 0;
108
+ const { recordCount: totalWritten } = await writeRecordsToCsvFile(filterAndMapHistoryRecords(queryRecords(targetOrgConnection, soql), filterConfig, parentFieldName, soqlFilterableFields, () => {
109
+ totalQueried++;
110
+ }), outputPath, CSV_COLUMNS);
111
+ this.spinner.stop();
112
+ this.info(messages.getMessage('info.complete', [totalQueried, totalWritten, outputPath]));
113
+ return { object, historyObject, totalQueried, totalWritten, path: outputPath };
114
+ }
115
+ }
116
+ function buildTimestamp() {
117
+ const now = new Date();
118
+ const pad = (n) => n.toString().padStart(2, '0');
119
+ return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}_${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
120
+ }
121
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../../../../src/commands/simply/sobject/history/query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC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1F,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IACjF,CAAC;;AAGH,SAAS,cAAc;IACrB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,GAAG,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACjE,OAAO,GAAG,GAAG,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAG,GAAG,CACrG,GAAG,CAAC,UAAU,EAAE,CACjB,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { FilterGroup } from '../schemas/history/filterConfig.js';
2
+ /**
3
+ * Derive the field history object's API name for an sobject. Opportunity is a special case —
4
+ * its history object is `OpportunityFieldHistory`, not `OpportunityHistory`.
5
+ */
6
+ export declare function getHistoryObjectName(sobject: string): string;
7
+ /** Derive the field history object's lookup field back to the parent record. */
8
+ export declare function getParentIdField(sobject: string): string;
9
+ /**
10
+ * Build a SOQL WHERE clause from the subset of a filter tree that references SOQL-filterable
11
+ * fields. Conditions on any other field are left for {@link recordMatchesClientFilters} to
12
+ * apply after the query runs.
13
+ */
14
+ export declare function buildWhereClause(node: FilterGroup | undefined, parentFieldName: string, soqlFilterableFields: ReadonlySet<string>): string;
15
+ /**
16
+ * Evaluate whether a queried record satisfies the parts of a filter tree that reference fields
17
+ * *not* covered by the SOQL WHERE clause (e.g. OldValue/NewValue). Conditions on SOQL-filterable
18
+ * fields are treated as already satisfied, since the query itself enforced them.
19
+ */
20
+ export declare function recordMatchesClientFilters(record: Record<string, string>, node: FilterGroup | undefined, parentFieldName: string, soqlFilterableFields: ReadonlySet<string>): boolean;
@@ -0,0 +1,139 @@
1
+ /*
2
+ * Copyright (c) 2026, Clay Chipps; Copyright (c) 2026 Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Derive the field history object's API name for an sobject. Opportunity is a special case —
18
+ * its history object is `OpportunityFieldHistory`, not `OpportunityHistory`.
19
+ */
20
+ export function getHistoryObjectName(sobject) {
21
+ if (sobject === 'Opportunity') {
22
+ return 'OpportunityFieldHistory';
23
+ }
24
+ if (sobject.endsWith('__c')) {
25
+ return `${sobject.slice(0, -3)}__History`;
26
+ }
27
+ return `${sobject}History`;
28
+ }
29
+ /** Derive the field history object's lookup field back to the parent record. */
30
+ export function getParentIdField(sobject) {
31
+ if (sobject === 'Opportunity') {
32
+ return 'OpportunityId';
33
+ }
34
+ if (sobject.endsWith('__c')) {
35
+ return 'ParentId';
36
+ }
37
+ return `${sobject}Id`;
38
+ }
39
+ function isFilterGroup(filter) {
40
+ return 'logic' in filter;
41
+ }
42
+ function resolveFieldName(field, parentFieldName) {
43
+ return field === 'ParentId' ? parentFieldName : field;
44
+ }
45
+ function formatSoqlValue(operator, value, isDateField) {
46
+ if (operator === 'IN' || operator === 'NOT IN') {
47
+ const values = Array.isArray(value) ? value : [value];
48
+ return `(${values.map((v) => (typeof v === 'string' ? `'${v}'` : String(v))).join(',')})`;
49
+ }
50
+ if (typeof value === 'string' && !isDateField) {
51
+ return `'${value}'`;
52
+ }
53
+ return String(value);
54
+ }
55
+ /**
56
+ * Build a SOQL WHERE clause from the subset of a filter tree that references SOQL-filterable
57
+ * fields. Conditions on any other field are left for {@link recordMatchesClientFilters} to
58
+ * apply after the query runs.
59
+ */
60
+ export function buildWhereClause(node, parentFieldName, soqlFilterableFields) {
61
+ if (!node || node.filters.length === 0) {
62
+ return '';
63
+ }
64
+ const clause = node.filters
65
+ .map((filter) => {
66
+ if (isFilterGroup(filter)) {
67
+ const nested = buildWhereClause(filter, parentFieldName, soqlFilterableFields);
68
+ return nested ? `(${nested})` : '';
69
+ }
70
+ const field = resolveFieldName(filter.field, parentFieldName);
71
+ if (!soqlFilterableFields.has(field)) {
72
+ return '';
73
+ }
74
+ const value = formatSoqlValue(filter.operator, filter.value, field === 'CreatedDate');
75
+ return `${field} ${filter.operator} ${value}`;
76
+ })
77
+ .filter((part) => part.length > 0)
78
+ .join(` ${node.logic} `);
79
+ return clause;
80
+ }
81
+ function escapeLikePattern(pattern) {
82
+ return pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/%/g, '.*');
83
+ }
84
+ function compareValues(recordValue, filterValue, operator) {
85
+ if (operator === 'IN' || operator === 'NOT IN') {
86
+ const values = Array.isArray(filterValue) ? filterValue : [filterValue];
87
+ const isMember = values.some((value) => String(value) === recordValue);
88
+ return operator === 'IN' ? isMember : !isMember;
89
+ }
90
+ if (operator === 'LIKE') {
91
+ return new RegExp(`^${escapeLikePattern(String(filterValue))}$`).test(recordValue ?? '');
92
+ }
93
+ // record values are always strings (queryRecords() normalizes both the REST and Bulk API
94
+ // paths to strings), so numeric/date comparisons need explicit coercion back to numbers —
95
+ // otherwise e.g. "9" > "10" would be true, and "5" === 5 would never match.
96
+ const numericRecord = recordValue !== undefined && recordValue !== '' ? Number(recordValue) : NaN;
97
+ const numericFilter = typeof filterValue === 'number' ? filterValue : Number(filterValue);
98
+ const bothNumeric = !Number.isNaN(numericRecord) && !Number.isNaN(numericFilter);
99
+ const left = bothNumeric ? numericRecord : (recordValue ?? '');
100
+ const right = bothNumeric ? numericFilter : String(filterValue);
101
+ switch (operator) {
102
+ case '=':
103
+ return left === right;
104
+ case '!=':
105
+ return left !== right;
106
+ case '>':
107
+ return left > right;
108
+ case '<':
109
+ return left < right;
110
+ case '>=':
111
+ return left >= right;
112
+ case '<=':
113
+ return left <= right;
114
+ default:
115
+ return false;
116
+ }
117
+ }
118
+ /**
119
+ * Evaluate whether a queried record satisfies the parts of a filter tree that reference fields
120
+ * *not* covered by the SOQL WHERE clause (e.g. OldValue/NewValue). Conditions on SOQL-filterable
121
+ * fields are treated as already satisfied, since the query itself enforced them.
122
+ */
123
+ export function recordMatchesClientFilters(record, node, parentFieldName, soqlFilterableFields) {
124
+ if (!node || node.filters.length === 0) {
125
+ return true;
126
+ }
127
+ const matches = (filter) => {
128
+ if (isFilterGroup(filter)) {
129
+ return recordMatchesClientFilters(record, filter, parentFieldName, soqlFilterableFields);
130
+ }
131
+ const field = resolveFieldName(filter.field, parentFieldName);
132
+ if (soqlFilterableFields.has(field)) {
133
+ return true;
134
+ }
135
+ return compareValues(record[field], filter.value, filter.operator);
136
+ };
137
+ return node.logic === 'AND' ? node.filters.every(matches) : node.filters.some(matches);
138
+ }
139
+ //# sourceMappingURL=fieldHistory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldHistory.js","sourceRoot":"","sources":["../../src/common/fieldHistory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,IAAI,OAAO,KAAK,aAAa,EAAE,CAAC;QAC9B,OAAO,yBAAyB,CAAC;IACnC,CAAC;IAED,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED,OAAO,GAAG,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CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzF,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ export declare const FilterConditionSchema: z.ZodObject<{
3
+ field: z.ZodString;
4
+ operator: z.ZodEnum<{
5
+ "=": "=";
6
+ "!=": "!=";
7
+ ">": ">";
8
+ "<": "<";
9
+ ">=": ">=";
10
+ "<=": "<=";
11
+ IN: "IN";
12
+ "NOT IN": "NOT IN";
13
+ LIKE: "LIKE";
14
+ }>;
15
+ value: z.ZodUnknown;
16
+ }, z.core.$strip>;
17
+ export type FilterCondition = z.infer<typeof FilterConditionSchema>;
18
+ export type FilterGroup = {
19
+ logic: 'AND' | 'OR';
20
+ filters: Array<FilterCondition | FilterGroup>;
21
+ };
22
+ export declare const FilterGroupSchema: z.ZodType<FilterGroup>;
23
+ export type FilterConfig = FilterGroup;
24
+ export declare const FilterConfigSchema: z.ZodType<FilterGroup, unknown, z.core.$ZodTypeInternals<FilterGroup, unknown>>;
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) 2026, Clay Chipps; Copyright (c) 2026 Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { z } from 'zod';
17
+ export const FilterConditionSchema = z.object({
18
+ field: z.string(),
19
+ operator: z.enum(['=', '!=', '>', '<', '>=', '<=', 'IN', 'NOT IN', 'LIKE']),
20
+ value: z.unknown(),
21
+ });
22
+ // Filter groups nest arbitrarily (a group's `filters` array can itself contain groups), so the
23
+ // schema has to reference itself. z.lazy() defers evaluation of the inner schema until it's
24
+ // actually used, which is what makes the self-reference possible.
25
+ export const FilterGroupSchema = z.lazy(() => z.object({
26
+ logic: z.enum(['AND', 'OR', 'and', 'or']).transform((value) => value.toUpperCase()),
27
+ filters: z.array(z.union([FilterConditionSchema, FilterGroupSchema])),
28
+ }));
29
+ export const FilterConfigSchema = FilterGroupSchema;
30
+ //# sourceMappingURL=filterConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterConfig.js","sourceRoot":"","sources":["../../../src/schemas/history/filterConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3E,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE;CACnB,CAAC,CAAC;AASH,+FAA+F;AAC/F,4FAA4F;AAC5F,kEAAkE;AAClE,MAAM,CAAC,MAAM,iBAAiB,GAA2B,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CACnE,CAAC,CAAC,MAAM,CAAC;IACP,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAkB,CAAC;IACnG,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,CAAC,CAAC;CACtE,CAAC,CACH,CAAC;AAIF,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC"}
@@ -0,0 +1,61 @@
1
+ # summary
2
+
3
+ Export field history for an SObject within a date range to a CSV file.
4
+
5
+ # description
6
+
7
+ Queries the field history object for the given SObject (e.g. `AccountHistory`, `Custom_Object__History`, or `OpportunityFieldHistory`) for changes created within the given date range, and writes the results to a timestamped CSV file.
8
+
9
+ # flags.sobject.summary
10
+
11
+ SObject API name
12
+
13
+ # flags.sobject.description
14
+
15
+ The API name of the SObject to export field history for (e.g. Account or Custom_Object__c).
16
+
17
+ # flags.start-date.summary
18
+
19
+ Start date (YYYY-MM-DD)
20
+
21
+ # flags.start-date.description
22
+
23
+ The start of the date range to export history for, inclusive.
24
+
25
+ # flags.end-date.summary
26
+
27
+ End date (YYYY-MM-DD)
28
+
29
+ # flags.end-date.description
30
+
31
+ The end of the date range to export history for, inclusive.
32
+
33
+ # flags.output-dir.summary
34
+
35
+ Output directory
36
+
37
+ # flags.output-dir.description
38
+
39
+ The directory to save the exported CSV file to. Defaults to the current directory.
40
+
41
+ # examples
42
+
43
+ - <%= config.bin %> <%= command.id %> --target-org myOrg --sobject Account --start-date 2026-01-01 --end-date 2026-01-31
44
+
45
+ - <%= config.bin %> <%= command.id %> --target-org myOrg --sobject Custom_Object__c --start-date 2026-01-01 --end-date 2026-01-31 --output-dir exports
46
+
47
+ # error.targetOrgConnectionFailed
48
+
49
+ Unable to establish connection to the org.
50
+
51
+ # error.invalidDate
52
+
53
+ Invalid value for --%s: "%s". Expected a date in YYYY-MM-DD format.
54
+
55
+ # info.exportingHistory
56
+
57
+ Exporting history for %s...
58
+
59
+ # info.complete
60
+
61
+ Exported %s history records to: %s
@@ -0,0 +1,63 @@
1
+ # summary
2
+
3
+ Query the field history of an SObject, with optional filtering.
4
+
5
+ # description
6
+
7
+ Queries the field history object for the given SObject (e.g. `AccountHistory`, `Custom_Object__History`, or `OpportunityFieldHistory`) and writes the results to a timestamped CSV file. An optional filter tree can be supplied to narrow the results: conditions on Field, CreatedById, CreatedDate, or the parent lookup field are pushed into the SOQL WHERE clause; conditions on any other field (e.g. OldValue or NewValue) are applied client-side after the query runs.
8
+
9
+ # flags.object.summary
10
+
11
+ SObject API name
12
+
13
+ # flags.object.description
14
+
15
+ The API name of the SObject to query field history for (e.g. Account or Custom_Object__c).
16
+
17
+ # flags.filters.summary
18
+
19
+ Path to a filter configuration file, or a raw JSON filter string
20
+
21
+ # flags.filters.description
22
+
23
+ A JSON object describing a tree of filter conditions: `{ "logic": "AND", "filters": [ { "field": "Field", "operator": "=", "value": "Status__c" } ] }`. Each entry in `filters` is either a condition (`field`, `operator`, `value`) or another nested group with its own `logic`/`filters`. Supported operators are =, !=, >, <, >=, <=, IN, NOT IN, and LIKE (using `%` as a wildcard).
24
+
25
+ # flags.output-dir.summary
26
+
27
+ Output directory
28
+
29
+ # flags.output-dir.description
30
+
31
+ The directory to save the query results CSV file to. Defaults to the current directory.
32
+
33
+ # examples
34
+
35
+ - <%= config.bin %> <%= command.id %> --target-org myOrg --object Account
36
+
37
+ - <%= config.bin %> <%= command.id %> --target-org myOrg --object Custom_Object__c --filters config/history-filters.json
38
+
39
+ - <%= config.bin %> <%= command.id %> --target-org myOrg --object Account --filters '{"logic":"AND","filters":[{"field":"Field","operator":"=","value":"Name"}]}'
40
+
41
+ # error.targetOrgConnectionFailed
42
+
43
+ Unable to establish connection to the org.
44
+
45
+ # error.invalidFiltersJson
46
+
47
+ Invalid filter configuration: %s
48
+
49
+ # error.invalidFilters
50
+
51
+ Filter configuration failed validation: %s
52
+
53
+ # info.generatedSoql
54
+
55
+ Generated SOQL: %s
56
+
57
+ # info.queryingHistory
58
+
59
+ Querying %s records...
60
+
61
+ # info.complete
62
+
63
+ Queried %s records; wrote %s records to %s after filtering
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simplysf/simply-sobject",
3
3
  "description": "Utilities for working with SObjects",
4
- "version": "1.2.1",
4
+ "version": "1.3.1",
5
5
  "author": "@ClayChipps",
6
6
  "homepage": "https://github.com/SimplySF/simply",
7
7
  "bugs": "https://github.com/SimplySF/simply/issues",
@@ -48,7 +48,12 @@
48
48
  "description": "Commands for simplifying Salesforce",
49
49
  "subtopics": {
50
50
  "sobject": {
51
- "description": "Commands for working with SObjects"
51
+ "description": "Commands for working with SObjects",
52
+ "subtopics": {
53
+ "history": {
54
+ "description": "Commands for working with SObject field history"
55
+ }
56
+ }
52
57
  }
53
58
  }
54
59
  }
@@ -60,7 +65,7 @@
60
65
  "@salesforce/core": "^8.30.0",
61
66
  "@salesforce/kit": "^3.2.6",
62
67
  "@salesforce/sf-plugins-core": "^12.2.16",
63
- "@simplysf/simply-core": "^1.1.1",
68
+ "@simplysf/simply-core": "^1.1.2",
64
69
  "zod": "^4.1.12"
65
70
  },
66
71
  "devDependencies": {
@@ -81,10 +86,10 @@
81
86
  "lint": "wireit",
82
87
  "readme": "oclif readme --no-aliases",
83
88
  "test": "wireit",
84
- "test:coverage": "vitest run --coverage",
85
- "test:nuts": "vitest run --config vitest.nuts.config.ts",
89
+ "test:coverage": "vitest run --coverage --project simply-sobject",
90
+ "test:nuts": "vitest run --config vitest.nuts.config.ts --project simply-sobject",
86
91
  "test:only": "wireit",
87
- "test:watch": "vitest watch"
92
+ "test:watch": "vitest watch --project simply-sobject"
88
93
  },
89
94
  "wireit": {
90
95
  "build": {
@@ -99,6 +104,7 @@
99
104
  "files": [
100
105
  "src/**/*.ts",
101
106
  "**/tsconfig.json",
107
+ "../../tsconfig.json",
102
108
  "messages/**"
103
109
  ],
104
110
  "output": [
@@ -125,7 +131,9 @@
125
131
  "test/**/*.ts",
126
132
  "messages/**",
127
133
  "**/.eslint*",
128
- "**/tsconfig.json"
134
+ "**/tsconfig.json",
135
+ "../../eslint.config.mjs",
136
+ "../../tsconfig.json"
129
137
  ],
130
138
  "output": []
131
139
  },
@@ -174,12 +182,13 @@
174
182
  "command": "tsc -p \"./test\" --pretty",
175
183
  "files": [
176
184
  "test/**/*.ts",
177
- "**/tsconfig.json"
185
+ "**/tsconfig.json",
186
+ "../../tsconfig.json"
178
187
  ],
179
188
  "output": []
180
189
  },
181
190
  "test:only": {
182
- "command": "vitest run",
191
+ "command": "vitest run --project simply-sobject",
183
192
  "env": {
184
193
  "FORCE_COLOR": "2"
185
194
  },
@@ -187,6 +196,7 @@
187
196
  "test/**/*.ts",
188
197
  "src/**/*.ts",
189
198
  "**/tsconfig.json",
199
+ "../../tsconfig.json",
190
200
  "vitest.config.ts",
191
201
  "!*.nut.ts"
192
202
  ],
@@ -202,5 +212,5 @@
202
212
  "output": []
203
213
  }
204
214
  },
205
- "gitHead": "70f4d985059c96ff2bfd4fbd0427e14861436aaa"
215
+ "gitHead": "6e5db1bed0c9e9c78e3ce5acdb04c18306b1462a"
206
216
  }