Create and Run Anonymous Apex
Anonymous Apex is a feature through which you can run code snippets on demand without storing them as metadata.
- Open the Command Palette.
- Type SFDX: Create Anonymous Apex Script.
- Modify the sample script in the text editor to incorporate your own code.
- Save the file, which is saved under the
scriptsfolder.
-
Make sure that your script is open in the text editor.
-
To run the whole script, right-click in the text editor and select SFDX: Execute Anonymous Apex with Currently Open Editor. To run only a part of the code, highlight the code, right-click, and select SFDX: Execute Anonymous Apex with Editor's Selected Text.

Alternatively, you can also run these commands from the Command Palette when the script is open in the text editor.
After you run the script, the log appears in the output panel. To view the log in the Debug Log Viewer, click Open Log in the message.

The debug logs are stored under sfdx/tools/debug/logs in your org. Click a log to open it in the Log Viewer.
