Deploying to an Org
Deploy Lightning Web Components to a Salesforce org with the Salesforce CLI, source tracking, and metadata deploys.
Deploying to an org
A component isn't useful until it's in an org, and the modern way to get it there is the Salesforce CLI (sf) working against a source-format project. You develop locally in VS Code with the Salesforce Extension Pack, keep your metadata in version control, and deploy to orgs on demand. There are two common workflows: scratch orgs with source tracking for development, and direct metadata deploys to persistent orgs like sandboxes and production.
First you authorise an org so the CLI can talk to it, then deploy your source. During development against a scratch or tracked org you can push and pull changes; against a sandbox or production you deploy a specified set of metadata.
# Authorise a sandbox or production org (opens a browser login)
sf org login web --alias myorg --instance-url https://test.salesforce.com
# Deploy the LWC (and related metadata) to that org
sf project deploy start --source-dir force-app/main/default/lwc --target-org myorg
# For scratch-org development with source tracking:
sf project deploy start --target-org scratchOrg # push local changes
sf project retrieve start --target-org scratchOrg # pull org changes
# Run local Jest tests before deploying
npm run test:unit
# Run Apex tests in the org after deploy
sf apex run test --target-org myorg --wait 10 --result-format human
A few practices keep deployments smooth. Deploy the whole feature, not just the component: an LWC often depends on Apex classes, custom fields, and permission sets, so include them or the deploy fails. Validate before you commit to production with a check-only deploy (--dry-run) and run the required Apex tests, since production deploys must meet the 75% coverage rule. Use source tracking in scratch orgs and sandboxes so the CLI knows exactly what changed, avoiding accidental overwrites.
For team delivery, wire these commands into a CI/CD pipeline so every change is validated and deployed automatically, and manage promotion from sandbox to production through version control rather than manual clicks. That completes the LWC journey: you can now build a component, make it reactive, wire in real data, add navigation and feedback, test it with Jest, and deploy it to any org. From here, keep building — the best way to cement all of this is to ship a small component of your own into a Developer org today.