-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: greenkeeper[bot] <23040076+greenkeeper[bot]@users.noreply.github.com> Co-authored-by: snyk-bot <[email protected]> Co-authored-by: Adam Osiecki <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Snyk bot <[email protected]> Co-authored-by: Adam Osiecki <[email protected]>
- Loading branch information
1 parent
9fe671b
commit d0d7673
Showing
6 changed files
with
1,557 additions
and
1,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,17 +58,19 @@ sfdx plugins:link | |
## Commands | ||
|
||
<!-- commands --> | ||
* [`sfdx oa:apex:log:delete [-c] [-a] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-oaapexlogdelete--c--a--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal) | ||
* [`sfdx oa:apex:log:delete [-c] [-a] [-s <array>] [-n <array>] [-m] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-oaapexlogdelete--c--a--s-array--n-array--m--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal) | ||
* [`sfdx oa:data:soql:sel -f <string> [-w <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-oadatasoqlsel--f-string--w-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal) | ||
|
||
## `sfdx oa:apex:log:delete [-c] [-a] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` | ||
## `sfdx oa:apex:log:delete [-c] [-a] [-s <array>] [-n <array>] [-m] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` | ||
|
||
delete ApexLog entries from Your org | ||
|
||
``` | ||
delete ApexLog entries from Your org | ||
USAGE | ||
$ sfdx oa:apex:log:delete [-c] [-a] [-u <string>] [--apiversion <string>] [--json] [--loglevel | ||
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL] | ||
$ sfdx oa:apex:log:delete [-c] [-a] [-s <array>] [-n <array>] [-m] [-u <string>] [--apiversion <string>] [--json] | ||
[--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL] | ||
OPTIONS | ||
-a, --async do not wait for successful | ||
|
@@ -80,6 +82,14 @@ OPTIONS | |
number of debug logs without | ||
deleting them | ||
-m, --my delete only my logs | ||
-n, --name=name delete only logs created by | ||
specified user names | ||
-s, --status=status delete only logs with specified | ||
statuses | ||
-u, --targetusername=targetusername username or alias for the target | ||
org; overrides default target org | ||
|
@@ -117,13 +127,24 @@ EXAMPLES | |
"jobID": "7501w000002WnWcAAK" | ||
} | ||
} | ||
sfdx oa:apex:log:delete -s "Internal Salesforce.com Error,success" | ||
Query: SELECT Id FROM ApexLog WHERE Status IN ('Internal Salesforce.com Error','success') does not return any | ||
record | ||
sfdx oa:apex:log:delete -m | ||
Query: SELECT Id FROM ApexLog WHERE LogUserId = '0054J000005OInNQAW' does not return any record | ||
oa:apex:log:delete -c -n [email protected],[email protected] | ||
Query: SELECT Id FROM ApexLog WHERE LogUser.Username IN ('[email protected]','[email protected]') does not return any | ||
record | ||
``` | ||
|
||
_See code: [lib\commands\oa\apex\log\delete.js](https://github.com/osieckiAdam/osiecki-sfdx-plugins/blob/v0.2.0/lib\commands\oa\apex\log\delete.js)_ | ||
_See code: [src/commands/oa/apex/log/delete.ts](https://github.com/osieckiAdam/osiecki-sfdx-plugins/blob/v0.2.1/src/commands/oa/apex/log/delete.ts)_ | ||
|
||
## `sfdx oa:data:soql:sel -f <string> [-w <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` | ||
|
||
generate query for all fields from SObject (SEL * FROM SObject) | ||
generate query string for all fields from SObject (SEL * FROM SObject) | ||
|
||
``` | ||
USAGE | ||
|
@@ -168,5 +189,4 @@ EXAMPLES | |
SystemModstamp, StartTime, Location FROM ApexLog WHERE Where LogLength > 100 | ||
``` | ||
|
||
_See code: [lib\commands\oa\data\soql\sel.js](https://github.com/osieckiAdam/osiecki-sfdx-plugins/blob/v0.2.0/lib\commands\oa\data\soql\sel.js)_ | ||
<!-- commandsstop --> | ||
_See code: [src/commands/oa/data/soql/sel.ts](https://github.com/osieckiAdam/osiecki-sfdx-plugins/blob/v0.2.1/src/commands/oa/data/soql/sel.ts)_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,23 +32,36 @@ sfdx oa:apex:log:delete --json' | |
"numberOfQueriedLogs": 3, | ||
"jobID": "7501w000002WnWcAAK" | ||
} | ||
} | ||
}`, | ||
` | ||
sfdx oa:apex:log:delete -s "Internal Salesforce.com Error,success" | ||
Query: SELECT Id FROM ApexLog WHERE Status IN ('Internal Salesforce.com Error','success') does not return any record`, | ||
` | ||
sfdx oa:apex:log:delete -m | ||
Query: SELECT Id FROM ApexLog WHERE LogUserId = '0054J000005OInNQAW' does not return any record`, | ||
` | ||
oa:apex:log:delete -c -n [email protected],[email protected] | ||
Query: SELECT Id FROM ApexLog WHERE LogUser.Username IN ('[email protected]','[email protected]') does not return any record` | ||
]; | ||
|
||
protected static requiresUsername = true; | ||
protected static flagsConfig = { | ||
checkonly: flags.boolean({ char: 'c', description: messages.getMessage('checkOnlyFlagDescription') }), | ||
async: flags.boolean({ char: 'a', description: messages.getMessage('asyncFlagDescription') }) | ||
async: flags.boolean({ char: 'a', description: messages.getMessage('asyncFlagDescription') }), | ||
status: flags.array({ char: 's', description: messages.getMessage('statusFlagDescription') }), | ||
name: flags.array({ char: 'n', description: messages.getMessage('nameFlagDescription') }), | ||
my: flags.boolean({ char: 'm', description: messages.getMessage('myFlagDescription') }) | ||
}; | ||
private queryString: string; | ||
|
||
public async run(): Promise<AnyJson> { | ||
|
||
let response: AnyJson = ({ numberOfQueriedLogs: 0 }); | ||
const conn = this.org.getConnection(); | ||
const apexLogRecords = await this.getAllApexLogs(); | ||
|
||
if (apexLogRecords.length > 0) { | ||
const apexLogRecords = await this.getApexLogs(conn); | ||
|
||
if (apexLogRecords && apexLogRecords.length > 0) { | ||
this.ux.log(messages.getMessage('recordsLenghtMessage', [apexLogRecords.length])); | ||
if (this.flags.checkonly) { | ||
response = ({ numberOfQueriedLogs: apexLogRecords.length }); | ||
|
@@ -57,23 +70,59 @@ sfdx oa:apex:log:delete --json' | |
response = await this.trackBatchProgress(batch, apexLogRecords.length); | ||
} | ||
} else { | ||
this.ux.log(messages.getMessage('noLogsMessage')); | ||
this.ux.log(messages.getMessage('query') + this.queryString + ' ' + messages.getMessage('doesNotReturnAnyRecord')); | ||
response = ({ numberOfQueriedLogs: 0 }); | ||
} | ||
return response; | ||
} | ||
|
||
public async getAllApexLogs() { | ||
const response = this.org.getConnection() | ||
public async getApexLogs(conn: core.Connection) { | ||
|
||
let query = this.org.getConnection() | ||
.sobject('ApexLog') | ||
.find({}, ['Id']) | ||
.execute({ autoFetch: true, maxFetch: 10000 }, async (err, records) => { | ||
return records; | ||
}); | ||
.find({}, ['Id']); | ||
|
||
const whereClause = await this.buildWhereClause(conn); | ||
if (whereClause) { | ||
query = query.where(whereClause); | ||
} | ||
this.queryString = await query.toSOQL((err, soql) => { | ||
return soql; | ||
}); | ||
|
||
const response = query.execute({ autoFetch: true, maxFetch: 20000 }, async (err, records) => { | ||
return records; | ||
}); | ||
return response; | ||
} | ||
|
||
public createBatch(conn: core.Connection, records: Array<{ Id?: string; }>): Batch { | ||
private async buildWhereClause(conn: core.Connection): Promise<string> { | ||
|
||
const whereClause: string[] = new Array<string>(); | ||
if (this.flags.my) { | ||
const identitystr = (await conn.identity()).user_id; | ||
whereClause.push("LogUserId = '" + identitystr + "'"); | ||
} else if (this.flags.name) { | ||
const formatedNames = this.flags.name.reduce((acc, currval) => { | ||
return acc + '\'' + currval + '\','; | ||
}, '').slice(0, -1); | ||
whereClause.push(`LogUser.Username IN (${formatedNames})`); | ||
} | ||
|
||
if (this.flags.status) { | ||
const formatedStatuses = this.flags.status.reduce((acc, currval) => { | ||
return acc + '\'' + currval + '\','; | ||
}, '').slice(0, -1); | ||
whereClause.push(`Status IN (${formatedStatuses})`); | ||
} | ||
|
||
if (whereClause.length) { | ||
return whereClause.join(' AND '); | ||
} | ||
return ''; | ||
} | ||
|
||
private createBatch(conn: core.Connection, records: Array<{ Id?: string; }>): Batch { | ||
return conn.bulk.createJob('ApexLog', 'delete').createBatch().execute(records); | ||
} | ||
|
||
|
Oops, something went wrong.