apex Commands
force:apex:class:create
Command Syntax
- sfdx force:apex:class:create
- [--json]
- [--loglevel LOGLEVEL]
- -n CLASSNAME
- [-t TEMPLATE]
- [-d OUTPUTDIR]
- [--apiversion APIVERSION]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -n | --classname CLASSNAME
- Required
-
The name of the new Apex class. The name can be up to 40 characters and must start with a letter.
- Type: string
- -t | --template TEMPLATE
- Optional
-
The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.
- Type: string
- Permissible values are: ApexException, ApexUnitTest, DefaultApexClass, InboundEmailService
- Default value: DefaultApexClass
- -d | --outputdir OUTPUTDIR
- Optional
-
The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.
- Type: string
- Default value: .
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
Help for force:apex:class:create
If not supplied, the apiversion, template, and outputdir use default values.
The outputdir can be an absolute path or relative to the current working directory.
Examples:
force:apex:trigger:create
Command Syntax
- sfdx force:apex:trigger:create
- [--json]
- [--loglevel LOGLEVEL]
- -n TRIGGERNAME
- [-t TEMPLATE]
- [-d OUTPUTDIR]
- [--apiversion APIVERSION]
- [-s SOBJECT]
- [-e TRIGGEREVENTS]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -n | --triggername TRIGGERNAME
- Required
-
The name of the new Apex trigger. The name can be up to 40 characters and must start with a letter.
- Type: string
- -t | --template TEMPLATE
- Optional
-
The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.
- Type: string
- Permissible values are: ApexTrigger
- Default value: ApexTrigger
- -d | --outputdir OUTPUTDIR
- Optional
-
The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.
- Type: string
- Default value: .
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
- -s | --sobject SOBJECT
- Optional
-
The sObject to create an Apex trigger on.
- Type: string
- Default value: SOBJECT
- -e | --triggerevents TRIGGEREVENTS
- Optional
-
The events that cause the trigger to fire.
- Type: array
- Default value: before insert
Help for force:apex:trigger:create
If not supplied, the apiversion, template, and outputdir use default values.
The outputdir can be an absolute path or relative to the current working directory.
Examples:
force:apex:execute
Command Syntax
- sfdx force:apex:execute
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [--apiversion APIVERSION]
- [-f APEXCODEFILE]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
- -f | --apexcodefile APEXCODEFILE
- Optional
-
Path to a local file that contains Apex code.
- Type: filepath
Help for force:apex:execute
Executes one or more lines of Apex code, or executes the code in a local file.
Before you enter code, run this command with no parameters to get a prompt.
From the prompt, all commands are executed in a single execute anonymous request.
For more information, see "Anonymous Blocks" in the Apex Developer Guide.
Examples:
force:apex:log:get
Command Syntax
- sfdx force:apex:log:get
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [--apiversion APIVERSION]
- [-c]
- [-i LOGID]
- [-n NUMBER]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
- -c | --color
- Optional
-
Applies default colors to noteworthy log lines.
- Type: boolean
- -i | --logid LOGID
- Optional
-
ID of the log to display.
- Type: id
- -n | --number NUMBER
- Optional
-
Number of most recent logs to display.
- Type: number
Help for force:apex:log:get
When you execute this command in a project, it fetches the specified log or given number of last logs from your default scratch org.
To get the IDs for your debug logs, run "sfdx force:apex:log:list".
To specify a count of logs to return, use the --number parameter to return the most recent logs.
Executing this command without parameters returns the most recent log.
Examples:
force:apex:log:list
Command Syntax
- sfdx force:apex:log:list
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [--apiversion APIVERSION]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
Help for force:apex:log:list
When you execute this command in a project, it lists the log IDs for your default scratch org.
Examples:
force:apex:log:tail
Command Syntax
- sfdx force:apex:log:tail
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [--apiversion APIVERSION]
- [-c]
- [-d DEBUGLEVEL]
- [-s]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
- -c | --color
- Optional
-
Applies default colors to noteworthy log lines.
- Type: boolean
- -d | --debuglevel DEBUGLEVEL
- Optional
-
Debug level to set on the DEVELOPER_LOG trace flag for your user.
- Type: string
- -s | --skiptraceflag
- Optional
-
Skips trace flag setup. Assumes that a trace flag and debug level are fully set up.
- Type: boolean
Help for force:apex:log:tail
Tails logs from your target org for 30 minutes.
If a DEVELOPER_LOG trace flag does not exist, this command creates one in the target org.
If the active trace flag's expiration date is within this command's timeout window, the command sets the trace flag's expiration date to 30 minutes from the current time.
The --debuglevel parameter assigns a debug level to the active DEVELOPER_LOG trace flag.
Use --skiptraceflag to skip trace flag setup, including setting expiration date and debug level. Include this flag only if there is an active user-based trace flag for your user.
The --json parameter emits log lines in JSON, but does not follow the standard Salesforce CLI JSON format (which includes status and result values).
Examples:
force:apex:test:report
Command Syntax
- sfdx force:apex:test:report
- [--json]
- [--loglevel LOGLEVEL]
- [-r RESULTFORMAT]
- [-u TARGETUSERNAME]
- [--apiversion APIVERSION]
- -i TESTRUNID
- [-c]
- [-d OUTPUTDIR]
- [-w WAIT]
- [--verbose]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -r | --resultformat RESULTFORMAT
- Optional
-
Format to use when displaying results. If you also specify the --json flag, --json overrides this parameter.
- Type: enum
- Permissible values are: human, tap, junit, json
- Default value: human
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
- -i | --testrunid TESTRUNID
- Required
-
The ID of test run.
- Type: id
- -c | --codecoverage
- Optional
-
Retrieves code coverage results.
- Type: boolean
- -d | --outputdir OUTPUTDIR
- Optional
-
Directory to store test run files.
- Type: directory
- -w | --wait WAIT
- Optional
-
Sets the streaming client socket timeout, in minutes. If the streaming client socket has no contact from the server for a number of minutes, the client exits. Specify a longer wait time if timeouts occur frequently.
- Type: minutes
- Default value: 6 minutes
- --verbose
- Optional
-
Displays Apex test processing details. If JSON format is specified, processing details aren’t displayed.
- Type: boolean
Help for force:apex:test:report
Displays test results for an enqueued or completed asynchronous Apex test run.
Examples:
force:apex:test:run
Command Syntax
- sfdx force:apex:test:run
- [--json]
- [--loglevel LOGLEVEL]
- [-r RESULTFORMAT]
- [-u TARGETUSERNAME]
- [--apiversion APIVERSION]
- [-n CLASSNAMES]
- [-s SUITENAMES]
- [-t TESTS]
- [-c]
- [-d OUTPUTDIR]
- [-l TESTLEVEL]
- [-w WAIT]
- [-y]
- [--verbose]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -r | --resultformat RESULTFORMAT
- Optional
-
Format to use when displaying results. If you also specify the --json flag, --json overrides this parameter.
- Type: enum
- Permissible values are: human, tap, junit, json
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
- -n | --classnames CLASSNAMES
- Optional
-
Comma-separated list of Apex test class names to run. You can specify only one of classnames, suitenames, or tests.
- Type: array
- -s | --suitenames SUITENAMES
- Optional
-
Comma-separated list of Apex test suite names to run. You can only specify one of classnames, suitenames, or tests.
- Type: array
- -t | --tests TESTS
- Optional
-
Comma-separated list of Apex test class names or IDs and test methods, if applicable, to run. You can only specify one of classnames, suitenames, or tests.
- Type: array
- -c | --codecoverage
- Optional
-
Retrieves code coverage results.
- Type: boolean
- -d | --outputdir OUTPUTDIR
- Optional
-
Directory to store test run files.
- Type: directory
- -l | --testlevel TESTLEVEL
- Optional
-
Specifies which tests to run, using one of these TestLevel enum values:
RunSpecifiedTests—Only the tests that you specify are run.
RunLocalTests—All tests in your org are run, except the ones that originate from installed managed packages.
RunAllTestsInOrg—All tests are in your org and in installed managed packages are run.
- Type: enum
- Permissible values are: RunLocalTests, RunAllTestsInOrg, RunSpecifiedTests
- -w | --wait WAIT
- Optional
-
Sets the streaming client socket timeout, in minutes. If the streaming client socket has no contact from the server for a number of minutes, the client exits. Specify a longer wait time if timeouts occur frequently.
- Type: minutes
- -y | --synchronous
- Optional
-
Runs test methods from a single Apex class synchronously. If you don't specify this flag, tests are run asynchronously.
- Type: boolean
- --verbose
- Optional
-
Displays Apex test processing details. If JSON format is specified, processing details aren’t displayed.
- Type: boolean
Help for force:apex:test:run
By default, runs all Apex tests in the org’s namespace.
To run specific test classes, specify class names or suite names, or set a --testlevel value.
To run specific test methods, use --tests.
Examples: