DEX450 CheatSheet
DEX450 CheatSheet
Table of Contents
Open the VS Code Command Palette using either of the following methods:
If you remove the leading > from the Command Palette, it turns into a file finder. This can also be
accessed using Ctrl + P or Cmd + P
Right-clicking files and directories in the Explorer view makes various context-sensitive options available.
The Salesforce Extensions Pack for VS Code adds options that are specific to Salesforce.
In the screenshot below, the user has clicked the force-app/main/default/classes directory
and the option SFDX: Create Apex Class is available among others. Different directories give different
options. For instance, the lwc directory allows you to create a Lightning web component. You can also
right-click individual files for their own options.
The Org Browser view allows you to retrieve individual components or all components for a given
metadata type without needing a package.xml. The org browser is only available for orgs that do not
have source tracking.
An anonymous block is Apex code that does not get stored in the metadata, but that can be compiled
and executed.
Reference: force:apex:execute
Use the force:apex:execute command to execute Apex code entered on the command line or
Apex code that exists in a local file.
A debug log can record database operations, system processes, and errors that occur when executing a
transaction or running unit tests. Learn more at the reference link above.
Select which Apex log you would like to download. They are presented in order of most recent to
least recent.
The force:apex:log:tail command activates debug logging and displays logs in the terminal. It
will tail logs from your target org for 30 minutes. If a DEVELOPER_LOG trace flag does not exist, it
automatically creates one in the target org.
Use a pipe to feed the output into the appropriate utility for your shell - either findstr, Select-
String, or grep - if you wish to filter the log. In this example, we filter for lines that contain
USER_DEBUG.
Replay debugger allows you to replay the steps of an Apex debug log and use traditional tools like
breakpoints and variable inspectors.
Enable the Replay Debugger by executing the following from the Command Palette:
> SFDX: Turn On Apex Debug Log for Replay Debugger
This will ensure that there is an active trace flag in your org with a log level of FINER or FINEST
for log category Visualforce and a log level of FINEST for log category Apex Code.
Confirm it worked by looking in the status bar (blue bar at bottom of VS Code) and verifying that it
says something like "Recording detailed logs until 10:02 PM".
Disable the Replay Debugger logs by executing the following from the Command Palette:
> SFDX: Turn Off Apex Debug Log for Replay Debugger
Confirm it worked by looking in the status bar (blue bar at bottom of VS Code) at observing that it
no longer mentions anything about detailed logs.
Set a checkpoint on a line of code by executing the following from the Command Palette:
> SFDX: Toggle Checkpoint
Right-click the left of the line where you wish to add the checkpoint.
Select "Add Conditional Breakpoint…".
Enter checkpoint for the Expression.
After setting the checkpoint, or any time you modify your Apex code in the same file, run the
following command to sync your checkpoint with the org to make sure the heap dump occurs:
> SFDX: Update Checkpoints in Org
In the list of Apex Tests, mouse over a class or test to reveal a green arrow.
If a test is missing, click the Refresh Tests button (circular arrow).
Click the arrow on a class row (run all tests in class) or a method row (run single test).
You can also run all tests in your org by clicking the green arrow in the TEST: APEX TESTS header.
After running a test with the Retrieve-test-code-coverage option enabled in your VS Code settings, open
the corresponding Apex class file and press the button in the Status Bar to toggle code coverage on and
off.
or right click the force-app/main/default/classes directory and select SFDX: Create Apex Class.
Enter a name for the class.
A list of directories will be presented. In most cases you will simply press Enter to accept the
default selection.
or right click the force-app/main/default/triggers directory and select SFDX: Create Apex Trigger.
Enter the name of the trigger that you would like to create.
A list of directories will be presented. In most cases you will simply press Enter to accept the
default selection.
or right click the force-app/main/default/aura directory and select SFDX: Create Aura Component.
Enter a name for the Aura component.
A list of directories will be presented. In most cases you will simply press Enter to accept the
default selection.
A directory will be created. This directory is known as the component bundle and will have every
possible file needed. You may wish to delete the files that you know you won't need.
or right click the force-app/main/default/lwc directory and select SFDX: Create Lightning Web
Component.
Enter a name for the Lightning web component.
A list of directories will be presented. In most cases you will simply press Enter to accept the
default selection.
A directory will be created with the template, controller, and metadata file.
or right click the force-app/main/default/pages directory and select SFDX: Create Visualforce Page.
Enter the name of the VF page that you would like to create.
A list of directories will be presented. In most cases you will simply press Enter to accept the
default selection.
Use the force:visualforce:page:create command to create a Visualforce page from the CLI.
Run the following CLI command, omitting the leading "/" if you are using Powershell:
sfdx force:org:open -p "/apex/yourPageName"
Prettier is a popular code formatter. It is recommended but not required for class.
Requirements
Helpful links:
In DEX450 Exercise 1-2, there is an optional step for setting up Prettier to work with Apex. Your
project already has an appropriately configured package.json. Prettier is set up in the
devDependencies and an entry has been created in the scripts block. When you run
npm install as advised in the instructions, you are installing both the prettier and prettier-
plugin-apex modules locally.
We provided a sample .prettierrc in the project. If you decide to change it, you can
format all files in your project at once by running the following command from the command
line at the root of your project.
npm run prettier -- --write "**/*.{trigger,cls,js,html}"
If you elect to install the prettier Apex plugin globally, you will need to enable the Prettier:
Resolve Global Modules setting in VS Code, but you will see that VS Code warns of a possible
performance impact.