Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 36 ยท Getting Started

Setting Up Your Developer Environment

Set up a free Salesforce Developer Edition org, the Developer Console, VS Code with Salesforce extensions and the sf CLI so you can write Apex today.

To write Apex you need three things: an org (a Salesforce environment to run code in), an editor, and a way to move code between them. This lesson sets up all three using free tools. Nothing here is runnable in the browser, so the commands are shown read-only, and the one runnable example is a small Java stand-in that models what a deploy does.

Step 1: get a free org

A Salesforce org is your own private copy of Salesforce with its own data, users and code. For learning, you want a Developer Edition org. It is free, never expires while you log in occasionally, and has most developer features switched on. Sign up through Salesforce's developer site, choose a username that looks like an email address (it does not need to be a real inbox, but it must be unique across all of Salesforce), and verify the account by email.

Other kinds of orgs you will meet later:

Org type Purpose
Developer Edition Free personal learning org
Scratch org Temporary org created from a definition file, ideal for source-driven teams
Sandbox Copy of production used for testing and staging
Production The live org real users work in

Step 2: the Developer Console

Every org includes the Developer Console, a browser tool: click the gear icon, then Developer Console. It lets you create classes and triggers, run snippets with Execute Anonymous, open debug logs and run tests. It is perfect for your first lessons because there is nothing to install.

Its limits: it is a basic editor, it does not work well with version control, and it cannot handle Lightning Web Components. Real projects use VS Code.

Step 3: VS Code and the Salesforce extensions

Install Visual Studio Code and then the Salesforce Extension Pack. It adds:

  • Apex syntax highlighting, code completion and an Apex language server
  • Commands to deploy, retrieve and run tests (press Ctrl+Shift+P, then type SFDX)
  • Lightning Web Components support
  • An org browser

You also need the Salesforce CLI (the sf command) and a recent Java JDK, because the Apex language server is written in Java. Check the CLI is installed:

Terminal
sf --version
sf org login web --alias mydevorg --set-default
sf org list

The second command opens a browser window where you log in to your org. The alias mydevorg is a nickname for it.

Step 4: create a project

A Salesforce project (an "SFDX project") is a folder with a fixed layout and a configuration file sfdx-project.json.

Terminal
sf project generate --name my-first-project
cd my-first-project

The important folders:

TEXT
my-first-project/
  sfdx-project.json          # project settings and API version
  force-app/main/default/
    classes/                 # Apex classes (.cls + .cls-meta.xml)
    triggers/                # Apex triggers
    lwc/                     # Lightning Web Components
    objects/                 # custom objects and fields
  config/project-scratch-def.json

Every Apex class is two files: Greeter.cls (the code) and Greeter.cls-meta.xml (the API version and status).

XML
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>62.0</apiVersion>
    <status>Active</status>
</ApexClass>

Step 5: deploy and retrieve

Your laptop holds the source; the org holds the running copy. You keep them in step with two commands:

Terminal
sf project deploy start --source-dir force-app    # laptop -> org
sf project retrieve start --source-dir force-app  # org -> laptop
flowchart LR
    L["Your project<br/>(VS Code + Git)"] -- "deploy" --> O["Salesforce org"]
    O -- "retrieve" --> L

Deploying copies code to the org, where it is compiled. If compilation fails, nothing is deployed.

That last sentence is worth proving. A deployment is all or nothing: Salesforce validates the whole set of components first. Here is a Java stand-in that models the idea.

Java Stand-in (Java): all-or-nothing deploy

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Keeping your code safe

Use Git from the start. Commit the force-app folder, and add a .forceignore file for things that should not be deployed. Never commit passwords or access tokens; the CLI stores its login separately, outside your project.

Choosing where to work

  • Following early lessons: the Developer Console is fine.
  • Anything with LWC, many files or teamwork: VS Code and the CLI.
  • Teams: scratch orgs plus Git, as covered in Deployment and CI.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is a Developer Edition org best used for?

    Developer Edition orgs are free personal environments for learning and building prototypes.
  2. 2. Which file holds the API version of an Apex class?

    Each class has a .cls file for code and a .cls-meta.xml file with its API version and status.
  3. 3. What happens if one component in a deployment fails to compile?

    Deployments are atomic. The platform validates everything and saves nothing if there is an error.
  4. 4. Which command downloads code from the org into your project?

    Retrieve pulls metadata from the org to your local source; deploy pushes it the other way.

Summary

  • A Developer Edition org is a free place to practise; sandboxes and scratch orgs serve teams.
  • The Developer Console needs no installation, but VS Code plus the sf CLI is the professional setup.
  • A project has a standard folder layout; each class is a .cls file plus a .cls-meta.xml file.
  • Deploy pushes local source to the org, retrieve pulls it back, and a failing deploy changes nothing.

Next: Your First Apex Code and Debug Logs