Skip to content

hardis:org:purge:apexlog

Description

Purges Apex debug logs from a Salesforce org.

This command provides a quick and efficient way to clear out accumulated Apex debug logs from your Salesforce environment. This is particularly useful for:

  • Storage Management: Freeing up valuable data storage space in your Salesforce org.
  • Performance Optimization: Reducing the overhead associated with large volumes of debug logs.
  • Troubleshooting: Ensuring that new debug logs are generated cleanly without interference from old, irrelevant logs.

Key functionalities:

  • Log Identification: Queries the ApexLog object to identify all existing debug logs.
  • Confirmation Prompt: Before deletion, it prompts for user confirmation, displaying the number of Apex logs that will be deleted.
  • Bulk Deletion: Uses the Salesforce Bulk API to efficiently delete a large number of Apex logs.
Technical explanations

The command's technical implementation involves:

  • SOQL Query: It executes a SOQL query (SELECT Id FROM ApexLog LIMIT 50000) to retrieve the IDs of Apex logs to be deleted. The limit is set to 50,000 to handle large volumes of logs.
  • CSV Export: The retrieved log IDs are temporarily exported to a CSV file (ApexLogsToDelete_*.csv) in the ./tmp directory.
  • User Confirmation: It uses the prompts library to ask for user confirmation before proceeding with the deletion, displaying the count of logs to be purged.
  • Bulk API Deletion: It then uses the Salesforce CLI's sf data delete bulk command, pointing to the generated CSV file, to perform the mass deletion of Apex logs.
  • File System Operations: It uses Node.js fs to create the temporary directory and manage the CSV file.
  • Error Handling: Includes error handling for the query and deletion operations.

Agent Mode

Supports non-interactive execution with --agent:

sf hardis:org:purge:apexlog --agent --target-org myorg@example.com

In agent mode:

  • All interactive prompts and confirmations are skipped.
  • Apex log deletion proceeds without confirmation.

Screenshots

Confirm the deletion of every Apex debug log of the org

Confirm the deletion of every Apex debug log of the org

1248 Apex debug logs of the Helios UAT sandbox deleted with the Bulk API

1248 Apex debug logs of the Helios UAT sandbox deleted with the Bulk API

Parameters

Name Type Description Default Required Options
agent boolean Run in non-interactive mode for agents and automation
debug
-d
boolean Activate debug mode (more logs)
flags-dir option Import flag values from a directory.
json boolean Format output as json.
prompt
-z
boolean Prompt for confirmation (true by default, use --no-prompt to skip)
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:purge:apexlog
$ sf hardis:org:purge:apexlog --target-org nicolas.vuillamy@gmail.com
$ sf hardis:org:purge:apexlog --agent

Comments