Get Started by Creating a New DX Project
This tutorial starts completely from scratch and shows you how to create simple artifacts, such as Apex classes and LWC components, and then how to sync them between your org and your local project on your laptop. Another tutorial to help you learn about source-driven development is Get Started by Using a Sample Repo, which is also hands-on but provides a ready-made application that's already in a GitHub repo. Both tutorials are a lot of fun.
Get an Org to Play With and Set It as Your Dev Hub
If you donât currently have an org in which you can play in, here are some options:
- Sign up for a free Developer Edition org here. Remember your username and password!
- Create a free Trailhead playground (also referred to as a Hands-on Org), which is just a Developer Edition org thatâs linked to your Trailhead account. Be sure you follow these instructions to get the username and password of your org.
Then follow these steps.
- Log in to your org from your browser by navigating to login.salesforce.com and enter your username and password.
-
In the top-right corner, click the gear icon and then Setup.

- In the Quick Find box on the left, enter Dev Hub, then click Dev Hub.
-
Click Enable Dev Hub.

Read more about it:
Install the Salesforce Platform Development Tools
-
Install Salesforce CLI on your computer.
Windows:
- Download the .exe file to your computer.
- Open Windows explorer and execute the downloaded *.exe file by double-clicking it and answering all the prompts.
macOS:
- Download the *.pkg file to your computer.
- Open Finder and execute the downloaded *.pkg file file by double-clicking it and answering all the prompts.
-
Open a command prompt (Windows) or terminal (macOS), and then run this CLI command to
make sure Salesforce CLI is installed correctly:
You see something like @salesforce/cli/2.98.6 darwin-arm64 node-v22.17.0.
- Install Visual Studio Code on your computer.
- Install the Salesforce Extensions into VS Code.
Create a Salesforce DX Project
-
In your command prompt (Windows) or terminal (macOS), change to a directory on your
computer where you want to create the DX project. For example, on macOS:
-
Create a Salesforce DX project called mydxproject by running this command:
-
Change to the directory that was created.
- sfdx-project.json: Main configuration file for your Salesforce DX project.
- config/project-scratch-def.json: Definition file for creating scratch orgs.
- .forceignore: File that specifies the source files you want to exclude when synchronizing metadata between your local project and org. If youâre familiar with Git, you can see that the file is very similar to the .gitignore file.
- force-app: Directory that contains source files that represent metadata from your org. The directory doesnât yet contain any files, but weâll add some later!
Read more about it:
Authorize Your Dev Hub and Create a Scratch Org
-
From your command prompt or terminal window, run this CLI command:
The --set-default-dev-hub and --alias flags declare this Dev Hub org as your default Dev Hub org and give it an alias. Later you see how specifying these flags now makes other CLI commands easier to use.
-
Log in to the org using your username and password in the window that pops up, just
like you log into any Salesforce org.
But wait, didnât you already log into this org? Yes, you did! But this time youâre logging into it via the org login web CLI command, which authorizes the org to be used by your local DX project. After youâre connected, you donât have to keep logging into the org when you run subsequent CLI commands.
-
Click Allow in the browser window that opens and asks if you allow access to the org.

You can close the browser window because youâre all done with it.
Back in your command prompt or terminal, you should see output like this, which confirms that you successfully authorized the org:
Successfully authorized joe@creative-fox-gw7irx.com with org ID 00Daj123457MzBEAU. -
In your command prompt or terminal, run this command to see the org you just
authorized, along with additional information about it, such as its org ID and Connected
status.
The little tree emoji (đł) to the left indicates that itâs your default Dev Hub org.
-
Run this command to create a scratch org using the default definition file that was
created in the Salesforce DX project:
Be sure you run the command from your main DX project directory, which in our example is /Users/juliet/sfdx/mydxproject.
As the command runs, the output tells you whatâs happening in the background as Salesforce creates the scratch org.
Similar to when you authorized the Dev Hub org, the --set-default and --alias flags set the scratch org as your default org and give it an alias. The scratch org creation process requires a Dev Hub, but because you previously set the one you authorized as your default, you donât need to specify it to the org create scratch command. Otherwise you must use the --target-dev-hub flag.
You see this message when the scratch org creation is finished:
-
Run this command again to see the new scratch org listed in the list of authorized
orgs:
The little leaf emoji (đ) to the left indicates that itâs your default org. Run this command to see details about your new org:
Read more about it:
Make a Change in Your Scratch Org And Retrieve It to Your Project
We donât go into details about how to use VS Code, which can do all kinds of amazing things. Check out this Trailhead module for more information. But we show you a few basics.
-
From your open command prompt or terminal, run this command to open your scratch org
in a browser:
Hold on, how did the CLI command know which org to open? Easy: when you created the scratch org, you specified that itâs your default org. If you want to open a different org, or be explicit about the default org, you use the --target-org flag and pass it a username or alias. For example:
-
In the browser that opens, use Object Manager to create a custom field with label
Account Status on the Account object. Choose any properties
about the field that you want, it doesnât matter for the purposes of this exercise.
Never done this task before? Follow this Trailhead Quick Look for details.
When youâre finished, you see something like this:

-
Open VS Code. An easy way is to run this command from your open command prompt or
terminal; the application opens right up:
- Click File -> Open Folder ..., navigate to your Salesforce DX project folder (which is /Users/juliet/sfdx/mydxproject in our example), and click Open.
-
On the left, under MYDXPROJECT, click the .forceignore file, which is in the root of your
Salesforce DX project directory. The contents of the file appears in a tab on the right.
You see something like this:

You use the .forceignore file to ignore files or directories when you run the CLI commands to deploy or retrieve source.
-
Click inside the .forceignore tab and add these
two lines at the end of the file after **/__tests__/**:
The reason weâre excluding Profiles from the source thatâs deployed and retrieved is that they can be finicky and itâs easier for now to just not worry about them. You also get some practice using the .forceignore file!
- Click File -> Save.
-
In the VS Code terminal, run this command to retrieve the customization you just
made:
If you donât have a terminal window open in VS Code, click View -> Terminal.
The retrieve might take a minute or two. But when itâs finished, you see something like this:

Similar to when you previously opened the scratch org, this CLI command knows to retrieve changed or new metadata from the scratch org because you set it as your default org.
The command output shows the metadata that it retrieved. You should see your new Account Status custom field. You probably also see other retrieved metadata, such as Layouts. Thatâs normal.
The Path column shows where the new metadata files are located in your project. Take a look at them if you want!
Read more about it:
Create an Apex Class and Deploy it To the Scratch Org
-
From VS Code, click View -> Command Palette and run
SFDX:Create Apex Class.
Enter MyApexClass for the Apex class name and store it in the default local source directory (force-app/main/default/classes).
A new tab opens on the right with initial code for MyApexClass, which is stored in a file called MyApexClass.cls. The command also created another file: MyApexClass.cls-meta.xml.
- (Optional) If youâre familiar with the Apex programming language, add some code to the new class. But you can also leave it empty for now; all we need for this exercise are the metadata files that correspond to the Apex class.
- Click File -> Save to save the new Apex class.
-
From the command palette, run SFDX: Push Source to Default
Org. (Deploying is sometimes also called pushing.)
You should see a notification like this when itâs complete:

Also check your output window (click View -> Output if you donât see it). You see information about the deploy, including the files that were actually deployed:
-
Go back to the browser window thatâs open to your scratch org. If you closed the
browser window, you can run this command again from the VS Code terminal:
- In the Setup Quick Find box, enter Apex, then click Apex Classes. You should see the MyApexClass Apex class you just created, but now itâs also in your scratch org. Pretty cool, huh!
-
For fun, letâs do one last thing: edit the Apex class in Setup. For example, add this
comment to the top of the file:
- In VS Code, go to the command palette and run SFDX: Pull Source from Default Org.
- When the retrieve (also sometimes called a pull) finishes, refresh the MyApexClass Apex class in VS Code if necessary; you should see the new comment that you made in Setup.
Read more about it:
Create a Lightning Web Component and Deploy it to the Scratch Org
-
From VS Code, click View -> Command Palette and run
SFDX:Create Lightning Web Component.
Enter helloworld for the filename and store it in the default directory (force-app/main/default/lwc).
A new tab opens on the right with initial code for the new LWC component, which is stored in a file called helloworld.js. The command also creats two other associated files (helloworld.html and helloworld.js-meta.xml) and a test.
- (Optional) If youâre familiar with creating Lightning Web Components, add some code to any of the helloworld files. But you can also leave them empty for now; all we need for this exercise are metadata files associated with the LWC component.
- Click File -> Save to save the new LWC component.
- From the command palette, run SFDX: Push Source to Default Org. Similar to when you deployed the Apex class, you see a notification and information in the Output window.
Read more about it:
Deploy All Customizations To a Sandbox
-
From the command prompt (Windows) or terminal (macOS) thatâs open in your Salesforce
DX project, run this command to deploy your changes to your Dev Hub.
The --source-dir flag specifies exactly what you want to deploy, which is all the metadata thatâs in the force-app package directory.
You see something like this:
-
Open the Dev Hub org in a browser window:
Use Object Manager and Setup to check that the new custom field (Account.Account_Status), Apex class (MyApexClass), and LWC component (helloworld) exist in the org.
Read more about it: