Salesforce CLI Command Reference
Release Notes
Deprecation Policy
apex get log
apex get test
apex list log
apex run
apex run test
apex tail log
apex trace create
apex trace delete
apex trace list
Create a trace flag for a user, Apex class, or Apex trigger.
Use trace flags to set up debug logging for a specified entity (user, Apex class, or Apex trigger). You must specify an existing debug level and the entity to trace. The trace flag expires after the specified duration (default 30 minutes).
To find the list of existing debug levels, run this Tooling API query on your org using the “data query” CLI command: “sf data query –query “SELECT DeveloperName FROM DebugLevel” –use-tooling-api”. To create a debug level in your org, see “Set Up Debug Logging” (https://help.salesforce.com/s/articleView?id=xcloud.code_add_users_debug_log.htm)
Use the –log-type flag to specify the type of debug log file to create; you have these two options:
After you create the trace flag, follow these steps to use it:
Perform the action that you want to debug. For example, if you created a trace flag for an Apex class, run the class.
Run the “apex log list” CLI command to get a list of the available debug logs in your org. Make note of the ID of the debug log you’re interested in.
Run the “apex log get” command and specify this ID log with the –log-id flag. You can also use the –number flag to get the most recent debug logs.
Examine the debug log for information about the entity you created a trace flag for. See “Debug Log” (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_debugging_debug_log.htm) for more information.
| Flag Name (Long) | Flag Name (Short) | Description |
|---|---|---|
‑‑api‑version | N/A | Type: Value Override the api version used for api requests made by this command |
‑‑debug‑level | ‑d | Type: Value Required Developer name of an existing debug level to apply. |
‑‑duration | N/A | Type: Value Default value: 30Duration, in minutes, before the trace flag expires. Maximum is 1440 (24 hours). |
‑‑flags‑dir | N/A | Type: Value Import flag values from a directory. |
‑‑json | N/A | Type: Boolean Format output as json. |
‑‑log‑type | ‑l | Type: Value Valid Values: DEVELOPER_LOG, USER_DEBUGDefault value: DEVELOPER_LOGType of trace flag to create. |
‑‑target‑org | ‑o | Type: Value Required Username or alias of the target org. Not required if the target-org configuration variable is already set. |
‑‑traced‑entity‑id | ‑i | Type: Value Required ID of the user, Apex class, or Apex trigger to trace. |
Create a trace flag for a user (ID starts with 005) with the SFDC_DevConsole debug level in your default org:
1sf apex trace create --traced-entity-id 005xx000001Svs8AAC --debug-level SFDC_DevConsoleCreate a USER_DEBUG trace flag that lasts 60 minutes in the org with alias “my-org”:
1sf apex trace create --traced-entity-id 005xx000001Svs8AAC --debug-level MyDebugLevel --log-type USER_DEBUG --duration 60 --target-org my-org