hardis:org:diagnose:unused-apex-classes
Description
List all async Apex classes (Batch,Queueable,Schedulable) that has not been called for more than 365 days.
The result class list probably can be removed from the project, and that will improve your test classes performances 😊
The number of unused day is overridable using --days option.
The command uses queries on AsyncApexJob and CronTrigger technical tables to build the result.
Apex Classes CreatedBy and CreatedOn fields are calculated from MIN(date from git, date from org)
This command is part of sfdx-hardis Monitoring and can output Grafana, Slack and MsTeams Notifications.
Agent Mode
Supports non-interactive execution with --agent:
sf hardis:org:diagnose:unused-apex-classes --agent --target-org myorg@example.com
In agent mode, the command runs fully automatically. The inactivity threshold defaults to 365 days when --days is not provided.
Screenshots
Batch, Queueable and Schedulable Apex classes of the Helios org not run for 365 days: none here
- (1) One row per async class, with the date of its latest job
Reports
The command writes these reports in the hardis-report folder of the project: a CSV file, and its Excel copy (XLSX) in the xls sub-folder.
Unused Apex classes
One row per batch, queueable or schedulable Apex class, with the date of its latest job and its creation date and author, so you can spot the ones not run for a long time.
Files: unused-apex-classes-*.csv, xls/unused-apex-classes-*.xlsx
Parameters
| Name | Type | Description | Default | Required | Options |
|---|---|---|---|---|---|
| agent | boolean | Run in non-interactive mode for agents and automation. Uses default values and skips prompts. | |||
| days -t |
option | Extracts the users that have been inactive for the amount of days specified. In CI, default is 180 days | |||
| debug -d |
boolean | Activate debug mode (more logs) | |||
| flags-dir | option | Import flag values from a directory. | |||
| json | boolean | Format output as json. | |||
| outputfile -f |
option | Force the path and name of output report file. Must end with .csv | |||
| skipauth | boolean | Skip authentication check when a default username is required | |||
| target-org -o |
option | Username or alias of the target org. Not required if the target-org configuration variable is already set. |
true | ||
| websocket | option | Websocket host:port for VsCode SFDX Hardis UI integration |
Examples
$ sf hardis:org:diagnose:unused-apex-classes
$ sf hardis:org:diagnose:unused-apex-classes --days 700
$ sf hardis:org:diagnose:unused-apex-classes --agent


