Skip to content

Commit 2e905ce

Browse files
committed
feat: display all record counts
1 parent 9557eb9 commit 2e905ce

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

messages/recordcounts.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"commandDescription": "display record counts for the specified standard and custom objects\nUse this command to get an approximate count of the records in standard or custom objects in your org. These record counts are the same as the counts listed in the Storage Usage page in Setup. The record counts are approximate because they're calculated asynchronously and your orgs storage usage isnt updated immediately.",
2+
"commandDescription": "display record counts for the specified standard and custom objects\nUse this command to get an approximate count of the records in standard or custom objects in your org. These record counts are the same as the counts listed in the Storage Usage page in Setup. The record counts are approximate because they're calculated asynchronously and your org's storage usage isn't updated immediately. Executing without the '--sobjecttype' flag will display all available record counts.",
33
"examples": [
4+
"sfdx force:limits:recordcounts:display",
45
"sfdx force:limits:recordcounts:display -s Account,Contact,Lead,Opportunity",
56
"sfdx force:limits:recordcounts:display -s Account,Contact -u [email protected]"
67
],

src/commands/force/limits/api/display.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import * as os from 'os';
88
import { SfdxCommand } from '@salesforce/command';
9-
import { Messages, SfdxError } from '@salesforce/core';
9+
import { Messages, SfError } from '@salesforce/core';
1010

1111
Messages.importMessagesDirectory(__dirname);
1212
const messages = Messages.loadMessages('@salesforce/plugin-limits', 'display');
@@ -48,7 +48,7 @@ export class LimitsApiDisplayCommand extends SfdxCommand {
4848

4949
return limits;
5050
} catch (err) {
51-
throw SfdxError.wrap(err);
51+
throw SfError.wrap(err);
5252
}
5353
}
5454
}

src/commands/force/limits/recordcounts/display.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import * as os from 'os';
88
import { flags, FlagsConfig, SfdxCommand, SfdxResult } from '@salesforce/command';
9-
import { Messages, SfdxError } from '@salesforce/core';
9+
import { Messages, SfError } from '@salesforce/core';
1010

1111
Messages.importMessagesDirectory(__dirname);
1212
const messages = Messages.loadMessages('@salesforce/plugin-limits', 'recordcounts');
@@ -39,28 +39,31 @@ export class LimitsRecordCountsDisplayCommand extends SfdxCommand {
3939
protected static readonly flagsConfig: FlagsConfig = {
4040
sobjecttype: flags.array({
4141
char: 's',
42-
required: true,
4342
description: messages.getMessage('sobjecttypeFlagDescription'),
4443
}),
4544
};
4645

4746
public async run(): Promise<RecordCount[]> {
4847
try {
49-
const sobjecttypeString = (this.flags.sobjecttype as string[]).join();
48+
const sobjectsPassed = this.flags.sobjecttype as string[];
49+
const sobjectsQuery = sobjectsPassed ? `=${sobjectsPassed.join()}` : '';
50+
5051
const conn = this.org.getConnection();
51-
const geturl = `${conn.baseUrl()}/limits/recordCount?sObjects=${sobjecttypeString}`;
52+
const geturl = `${conn.baseUrl()}/limits/recordCount?sObjects${sobjectsQuery}`;
5253
const result = await conn.request<Result>(geturl);
5354

5455
// if an object is requested, but there's 0 of them on the server, append that object to the result
55-
sobjecttypeString.split(',').forEach((name) => {
56-
if (!result.sObjects.find((record) => record.name === name)) {
57-
result.sObjects.push({ name, count: 0 });
58-
}
59-
});
56+
if (sobjectsPassed) {
57+
sobjectsPassed.forEach((name) => {
58+
if (!result.sObjects.find((record) => record.name === name)) {
59+
result.sObjects.push({ name, count: 0 });
60+
}
61+
});
62+
}
6063

6164
return result.sObjects;
6265
} catch (err) {
63-
throw SfdxError.wrap(err);
66+
throw SfError.wrap(err);
6467
}
6568
}
6669
}

test/commands/recordcounts.nut.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ describe('recordcounts:display', () => {
3838
expect(output.status).to.equal(0);
3939
});
4040

41+
it('Displays all records (json)', () => {
42+
const output = execCmd<RecordCount[]>(`force:limits:recordcounts:display -u ${username} --json`, {
43+
ensureExitCode: 0,
44+
}).jsonOutput;
45+
46+
expect(output.result).length.greaterThan(10);
47+
expect(output.status).to.equal(0);
48+
});
49+
4150
it('Displays the records (human readable)', () => {
4251
const command = `force:limits:recordcounts:display -s Account -u ${username}`;
4352
const result = execCmd(command, { ensureExitCode: 0 });

0 commit comments

Comments
 (0)