DX Complete Guide - Installation and Setup

1 - Salesforce DX - The Complete Guide - Introduction / Trailer

  • Salesforce DX stands for “Salesforce Developer Experience”
    • Created to streamline development and implement more Salesforce best practices
  • This course is designed to help people becomes fully-functional at using Salesforce DX
    • Installation, exploration how different pieces work and interact (scratch orgs, Salesforce CLI, Visual Studio Code, Unlocked packages)
    • Compares org-based development and package-based development
    • Introduces Apex triggers, classes, and other Salesforce-based code
    • Explores using Salesforce Development with Git and how to automate the development process using Continuous Integration and Continuous Delivery

2 - Create a Developer Edition Dev Hug

  • Start by going to developer.salesforce.com/signup and enter requested information
    • Will receive “Welcome to Salesforce: Verify your account” email with a “Verify Account” button, log in URL (ryanwingate-dev-ed.lightning.force.com for me), and username
      • Edition of org: Developer Edition, same as Trailhead orgs
  • Next step to set up the account to work with Salesforce DX:
    • Setup > Quick Find > “Dev Hub” > Dev Hub > Enable Dev Hub
      • Click toggle to Enable Dev Hub
        • Enables, the following, all of which
          1. Create and manage scratch orgs from the command line
          2. View information about your scratch orgs
          3. Link namespace orgs
      • Click toggle to Enable Unlocked Packages and Second-Generation Managed Packages
        • Allows us to use second-generation packaging, which is a type of packaging you can only create and modify using Salesforce DX

3 - Install Java

4 - Install Salesforce CLI

  • Ensure Salesforce CLI is installed with sfdx help or sfdx version

5 - Install Visual Studio Code and Plugins

  • Visual Studio Code is the preferred IDE to use for Salesforce development. Salesforce recommends it and supports the integration with Salesforce CLI.
  • To install extensions, click the “Extensions” pane, then search for “Salesforce.” Install the “Salesforce Extension Pack.”
    • The extension pack has been installed when typing Ctrl + Shift + P then SFDX in the resulting search window brings up a list of Salesforce DX commands.

6 - Creating a Salesforce DX Project

  • To close a Workspace in Salesforce DX, type Ctrl+K F. That is, CTRL+K, then F. It is a “chord” that closes the current folder.
  • To open a Terminal: Terminal > New Terminal
    • Vast majority of the commands that we will run can be run from the Terminal
    • sfdx -h opens help
    • To create a project, use sfdx force:project:create. Appending -h will open the help menu for the create project command.
  • Open the Command Palette with Ctrl+Shift+P. Helpful to run create project from the command palette because we can set the output directory by browsing instead of hard-coding the file location in the terminal.

  • Basic Salesforce DX project directory contents shown above:
    • .sfdx, .vscode contains different configurations and caching type info - will not be worked in.
    • config includes the scratch definition file. Will be referenced every time a scratch org is created.
    • force-app main folder to worry about and work with. Contains all metadata. Apex classes, lighting web components, custom objects, etc.
    • scripts contains “Execute Anonymous” statements and “SOQL” queries in text file form
    • .forceignore can include pieces of metadata that you don’t want to have in the scratch org. The source tracking ignores this.
    • .gitignore similar to above, but for git.
    • .prettierignore, .prettierrc relate to the prettier VS Code extension
    • README.md includes automatically-populated information from Salesforce. Should be updated to include info about the project.
    • sfdx-project.json is important. Any directories referenced here will be treated as packages and will be pushed to and from scratch orgs. These can also be used to create second generation scratch orgs.
sfdx-project.json...

{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true
    }
  ],
  "namespace": "",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "51.0"
}
  • Next step is to Authorize a Dev Hub via “Ctrl-Shift-P”, then “SFDX:Authorize a Dev Hub”
    • After successfully executing, the .sfdx/sfdx-config.json file will include a “defaultdevhubusername”

7 - Navigating VS Code

  • In the left-hand pane:
    • Explorer shows the file and directory hierarchy referenced in the previous section
    • Search lets you search for fields, for example
    • Source Control git, github integration
    • Debugging of Apex, etc.
    • Extensions shows the various VS Code extensions currently installed
    • Testing for Apex and Lightning Web Components
    • Not available in my VS Code at time of these notes, but available in AW’s:
      • Metadata Browser was in beta in AW’s video (Cloud Icon)
      • Conflicts allows us to detect conflicts between the org and the metadata in the project