If you are completely new to Salesforce development, this guide will help you set up a Salesforce DX project locally, connect it to your Salesforce sandbox, create your first Lightning Web Component (LWC), and deploy it successfully.
This guide is intentionally written in simple language so that even someone with zero coding setup experience can follow it step by step.
We will do this in small steps:
Install Salesforce development tools
Create a Salesforce DX project locally
Connect the project to a Salesforce sandbox
Retrieve Apex code from Salesforce
Create a Lightning Web Component (LWC)
Deploy the component to Salesforce
Add the component to Experience Cloud
Handle common deployment errors
This step-by-step approach is important because it helps you test one thing at a time instead of debugging everything together.
Salesforce DX is Salesforce’s modern development framework.
In simple words:
It lets developers write Salesforce code locally on their computer
Track changes using Git
Deploy code to Salesforce orgs
Work like professional software teams
Install these 3 tools first.
This is the editor where you will write Salesforce code.
This adds Salesforce support inside VS Code.
It helps with:
Apex development
Lightning Web Components
Deployments
Debugging
Org authentication
The Salesforce CLI allows your computer to communicate with Salesforce orgs using terminal commands.
After installing CLI, open PowerShell and run:
Get-ChildItem "C:\Program Files\sf"
Then:
Get-ChildItem "C:\Program Files\sf\bin"
You should see:
sf.cmd
or
sf.exe
Now validate installation:
& "C:\Program Files\sf\bin\sf.cmd" --version
If that fails, try:
& "C:\Program Files\sf\bin\sf.exe" --version
If sf --version does not work, your PATH variable is probably missing.
Search:
Environment Variables
Open:
Edit the system environment variables
Then:
Click "Environment Variables"
Under User Variables select Path
Click Edit
Click New
Add:
C:\Program Files\sf\bin
Click OK everywhere.
Close PowerShell and reopen it.
Now test:
sf --version
If you want to test quickly:
setx PATH "$($env:PATH);C:\Program Files\sf\bin"
Then run:
sf --version
Open:
Inside VS Code:
Terminal → New Terminal
cd "C:\Users\YourUserName\Documents"
Replace YourUserName with your Windows username.
Run:
sf project generate --name preference-center
This creates a standard Salesforce DX project.
Run:
code "C:\Users\YourUserName\Documents\preference-center"
You should now see:
preference-center
force-app
manifest
sfdx-project.json
The file:
sfdx-project.json
confirms this is a valid Salesforce DX project.
Now we connect your local project to Salesforce.
Run:
sf org login web --instance-url https://economist--mcn.sandbox.my.salesforce.com --alias mcnsandbox --set-default
What happens:
Browser opens
Salesforce login page appears
Login to sandbox
Click Allow
Return to VS Code
Run:
sf org list
You should see:
Your sandbox
Alias
Connected status
Default org
If you already created Apex inside Salesforce UI, pull it locally.
Example:
sf project retrieve start --metadata ApexClass:PreferenceCenterController
This downloads the Apex class into your local project.
We will create:
preferenceCenter
An LWC usually contains:
HTML
JavaScript
Metadata XML
Run:
sf lightning generate component --type lwc --name preferenceCenter --output-dir force-app/main/default/lwc
This automatically creates:
force-app/main/default/lwc/preferenceCenter
Inside it:
preferenceCenter.html
preferenceCenter.js
preferenceCenter.js-meta.xml
Alternative method:
Right-click lwc
Select:
SFDX: Create Lightning Web Component
Enter:
preferenceCenter
<template>
<div style="padding:20px;background:#ffffff;border-radius:8px;">
<h2>Manage Your Preferences</h2>
<p>This is my first Lightning Web Component.</p>
</div>
</template>
import { LightningElement } from 'lwc';
export default class PreferenceCenter extends LightningElement {}
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>66.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
</targets>
</LightningComponentBundle>
Without this:
<isExposed>true</isExposed>
your component will NOT appear in Experience Builder.
This is one of the most common beginner mistakes.
Run:
sf project deploy start --source-dir force-app/main/default/lwc/preferenceCenter --target-org mcnsandbox
If deployment succeeds, your component now exists in Salesforce.
Now go to your Experience Cloud site.
Open:
Experience Builder
On the left component panel, search:
preferenceCenter
Drag the component onto the page.
Then:
Save → Publish
You should now see:
Manage Your Preferences
This is my first Lightning Web Component.
on the page.
At this point, you have successfully:
Set up Salesforce DX
Connected sandbox
Created an LWC
Deployed code
Added component to Experience Cloud
That is a huge milestone for a beginner.
CLI PATH issue.
Add:
C:\Program Files\sf\bin
to Environment Variables PATH.
Wrong sandbox URL or login issue.
Use correct sandbox URL:
sf org login web --instance-url https://yourdomain--sandbox.sandbox.my.salesforce.com
Missing:
<isExposed>true</isExposed>
or wrong targets.
Ensure:
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
exist in XML file.
Syntax error in code.
Read terminal carefully.
Usually:
Missing semicolon
Invalid import
Wrong XML syntax
Salesforce CLI doesn't know where to deploy.
Run:
sf org login web --set-default
or:
sf config set target-org=mcnsandbox
sf org login web
sf org list
sf project retrieve start --metadata ApexClass:PreferenceCenterController
sf project deploy start --source-dir force-app/main/default/lwc/preferenceCenter
sf org display
sf org open
Do not try to learn everything together.
Best order:
Salesforce CLI
VS Code
Salesforce DX
Apex basics
Lightning Web Components
Deployment
Experience Cloud
Git and version control
This reduces confusion massively.
Most beginners struggle with Salesforce development because they try to:
build everything together
debug multiple problems at once
skip environment setup
Instead:
set up tools first
create a tiny component
deploy small changes
test one layer at a time
That is how professional Salesforce developers work in real projects.
sf org login web --instance-url https://economist--mcn.sandbox.my.salesforce.com --alias mcnsandbox --set-default
sf org list
sf project retrieve start --metadata ApexClass:PreferenceCenterController
sf lightning generate component --type lwc --name preferenceCenter --output-dir force-app/main/default/lwc
sf org login web --instance-url https://economist--mcn.sandbox.my.salesforce.com --alias mcnsandbox --set-default
to deploy: sf project deploy start --source-dir force-app/main/default/lwc/preferenceCenter --target-org mcnsandbox