Hello friends, Please go through earlier Chapters in the Series before starting this one.
Chapter 1: Introduction to Lightning Web Component
Chapter 2: Install Developer Tools for LWC
Chapter 3 : Setup SalesforceDX (SFDX) for Non-Scratch Orgs
In this Chapter we will learn how to use SFDX with Scratch Orgs
Topics Covered:
- Package Development Model
- Steps to Setup SalesforceDX (SFDX) for Scratch Orgs
Package Development Model: Allows you to create self-contained applications or libraries that are deployed to your org as a single package. These packages are typically developed against source-tracked orgs such as scratch orgs. This development model uses org source tracking, source control, and continuous integration and deployment.
What are Scratch Orgs
Salesforce DX introduces a new type of Salesforce environment in Scratch orgs. These are orgs consisting of Salesforce code or metadata that can be easily created or destroyed, helping to speed up the standard development workflow.
You can spin up a new scratch org when you want to:
- Start a new project.
- Start a new feature branch.
- Test a new feature.
- Start automated testing.
- Perform development tasks directly in an org.
- Start from “scratch” with a fresh new org
Advantages of Scratch Org
- They are Convenient: They can be created and destroyed quickly. Completely devoid of any data and metadata. It is clean slate
- They are Configurable: You can choose edition, features and preference
- They are disposable: You can delete when you are done
Scratch orgs do not replace sandboxes. Scratch orgs are not permanent and they don’t include any production data.
Scratch orgs complement Sandboxes. They are great for temporary deployments. We typically use them for peer review and a way to get enhanced test coverage and automation.
Step 1 : Create a New SF DX Project
Select Standard
Choose the folder in which you want to save the project
Give the project name
Your project is created in Visual Studio
Step 2 : Authorize a Dev Hub
A Dev Hub provides the ability to create and manage scratch orgs.
login to Salesforce Org
Step 3 : Enable Dev Hub
We have to enable Dev Hub to create a Scratch Org.
Now Create a default Scratch Org
Choose project-scratch-def.json
Give an org alias
Select no of days for scratch org. It can be between 1 to 30 days. By default it is 7 days
On right hand side you will be able to see that Scratch org is successfully running
Not select Open Default Org
Step 4 : Push and pull from Org
Create Apex Class
Enter name of class
You can see that class is created
Push Source in Default Scratch Org
Open class in the org to see that class is being created
Now make changes to the class
Pull Source from Default Scratch Org
You will see changes in the class
PPT for Salesforce DX for Scratch Orgs
Together we can learn faster
Join LWC study group on Telegram
Subscribe to Youtube channel and blog to get latest updates
Reference
Project Development Model Trailhead