Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
{
"command": "force:limits:api:display",
"plugin": "@salesforce/plugin-limits",
"flags": ["apiversion", "json", "loglevel", "targetusername"]
"flags": ["apiversion", "json", "loglevel", "targetusername"],
"alias": []
},
{
"command": "force:limits:recordcounts:display",
"plugin": "@salesforce/plugin-limits",
"flags": ["apiversion", "json", "loglevel", "targetusername", "sobjecttype"]
"flags": ["apiversion", "json", "loglevel", "sobjecttype", "targetusername"],
"alias": []
}
]
3 changes: 2 additions & 1 deletion messages/recordcounts.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"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.",
"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. To display all available record counts, run the command without the '--sobjecttype' parameter.",
"examples": [
"sfdx force:limits:recordcounts:display",
"sfdx force:limits:recordcounts:display -s Account,Contact,Lead,Opportunity",
"sfdx force:limits:recordcounts:display -s Account,Contact -u me@my.org"
],
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"name": "@salesforce/plugin-limits",
"description": "commands to display api limits to your org",
"version": "1.3.0",
"version": "2.0.0",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"main": "lib/index.js",
"dependencies": {
"@oclif/config": "^1",
"@salesforce/command": "^4.2.0",
"@salesforce/core": "^2.31.0",
"@oclif/core": "^1.6.3",
"@salesforce/command": "^5.0.4",
"@salesforce/core": "^3.10.1",
"tslib": "^2"
},
"devDependencies": {
"@oclif/dev-cli": "^1",
"@oclif/plugin-command-snapshot": "^2.0.0",
"@oclif/plugin-command-snapshot": "^3",
"@salesforce/cli-plugins-testkit": "^1.4.10",
"@salesforce/dev-config": "^3.0.0",
"@salesforce/dev-scripts": "^2.0.0",
Expand Down Expand Up @@ -67,6 +68,9 @@
"license": "BSD-3-Clause",
"oclif": {
"commands": "./lib/commands",
"additionalHelpFlags": [
"-h"
],
"bin": "sfdx",
"devPlugins": [
"@oclif/plugin-help",
Expand Down
12 changes: 3 additions & 9 deletions src/commands/force/limits/api/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import * as os from 'os';
import { SfdxCommand } from '@salesforce/command';
import { Messages, SfdxError } from '@salesforce/core';
import { Messages, SfError } from '@salesforce/core';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-limits', 'display');
Expand Down Expand Up @@ -44,17 +44,11 @@ export class LimitsApiDisplayCommand extends SfdxCommand {
});
});

this.ux.table(limits, {
columns: [
{ key: 'name', label: 'Name' },
{ key: 'remaining', label: 'Remaining' },
{ key: 'max', label: 'Max' },
],
});
this.ux.table(limits, { name: { header: 'Name' }, remaining: { header: 'Remaining' }, max: { header: 'Max' } });

return limits;
} catch (err) {
throw SfdxError.wrap(err);
throw SfError.wrap(err);
}
}
}
31 changes: 16 additions & 15 deletions src/commands/force/limits/recordcounts/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import * as os from 'os';
import { flags, FlagsConfig, SfdxCommand, SfdxResult } from '@salesforce/command';
import { Messages, SfdxError } from '@salesforce/core';
import { Messages, SfError } from '@salesforce/core';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-limits', 'recordcounts');
Expand All @@ -26,10 +26,8 @@ export class LimitsRecordCountsDisplayCommand extends SfdxCommand {
public static readonly requiresUsername = true;
public static readonly result: SfdxResult = {
tableColumnData: {
columns: [
{ key: 'name', label: 'sObject' },
{ key: 'count', label: 'Record Count' },
],
name: { header: 'sObject' },
count: { header: 'Record Count' },
},
display() {
if (Array.isArray(this.data) && this.data.length) {
Expand All @@ -41,28 +39,31 @@ export class LimitsRecordCountsDisplayCommand extends SfdxCommand {
protected static readonly flagsConfig: FlagsConfig = {
sobjecttype: flags.array({
char: 's',
required: true,
description: messages.getMessage('sobjecttypeFlagDescription'),
}),
};

public async run(): Promise<RecordCount[]> {
try {
const sobjecttypeString = (this.flags.sobjecttype as string[]).join();
const sobjectsPassed = this.flags.sobjecttype as string[];
const sobjectsQuery = sobjectsPassed ? `=${sobjectsPassed.join()}` : '';

const conn = this.org.getConnection();
const geturl = `${conn.baseUrl()}/limits/recordCount?sObjects=${sobjecttypeString}`;
const result = (await conn.request(geturl)) as unknown as Result;
const geturl = `${conn.baseUrl()}/limits/recordCount?sObjects${sobjectsQuery}`;
const result = await conn.request<Result>(geturl);

// if an object is requested, but there's 0 of them on the server, append that object to the result
sobjecttypeString.split(',').forEach((name) => {
if (!result.sObjects.find((record) => record.name === name)) {
result.sObjects.push({ name, count: 0 });
}
});
if (sobjectsPassed) {
sobjectsPassed.forEach((name) => {
if (!result.sObjects.find((record) => record.name === name)) {
result.sObjects.push({ name, count: 0 });
}
});
}

return result.sObjects;
} catch (err) {
throw SfdxError.wrap(err);
throw SfError.wrap(err);
}
}
}
2 changes: 1 addition & 1 deletion test/commands/display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { $$, test, expect } from '@salesforce/command/lib/test';

describe('force:limits:api:display', () => {
async function prepareStubs() {
$$.SANDBOX.stub(Org.prototype, 'getConnection').callsFake(() => Connection.prototype);
$$.SANDBOX.stub(Org.prototype, 'getConnection').returns(Connection.prototype);
$$.SANDBOX.stub(Connection.prototype, 'request').resolves({
AnalyticsExternalDataSizeMB: {
Max: 40960,
Expand Down
9 changes: 9 additions & 0 deletions test/commands/recordcounts.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ describe('recordcounts:display', () => {
expect(output.status).to.equal(0);
});

it('Displays all records (json)', () => {
const output = execCmd<RecordCount[]>(`force:limits:recordcounts:display -u ${username} --json`, {
ensureExitCode: 0,
}).jsonOutput;

expect(output.result).length.greaterThan(10);
expect(output.status).to.equal(0);
});

it('Displays the records (human readable)', () => {
const command = `force:limits:recordcounts:display -s Account -u ${username}`;
const result = execCmd(command, { ensureExitCode: 0 });
Expand Down
2 changes: 1 addition & 1 deletion test/commands/recordcounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { $$, test, expect } from '@salesforce/command/lib/test';

describe('force:limits:recordcounts:display', () => {
async function prepareStubs() {
$$.SANDBOX.stub(Org.prototype, 'getConnection').callsFake(() => Connection.prototype);
$$.SANDBOX.stub(Org.prototype, 'getConnection').returns(Connection.prototype);
$$.SANDBOX.stub(Connection.prototype, 'request').resolves({
sObjects: [
{ count: 34, name: 'Account' },
Expand Down
Loading