Once Visual Studio Code is setup. Lets go to Terminal window and through command prompt go to the desired directory of your computer. Now, lets run the command to create a DX project in your computer.
Now, to authorize the salesforce org as devhub org, first ensure your org is enabled as DevHub org. To check this, go to settings then search for Dev Hub and enabled this, if not.
Now in VS Code open terminal window and type below to authorize the Dev Hub org:
Authorizes a Salesforce org by opening a browser so you can log in through salesforce.com.
sfdx force:auth:web:login[–json][–loglevel LOGLEVEL][-i CLIENTID][-r INSTANCEURL][-d][-s][-a SETALIAS]
Tips: To log in to a sandbox, set –instanceurl to https://test.salesforce.com.
once authorized, check the default org name as per below navigation in VS Code.
Now, lets create the scratch org. Before we start to create a scratch org , first open config/project-scratch-def.json file and make below entry to ensure we have sample data ready for our scratch org when we create.
Now, lets fire the scratch org creation command:
PS C:\Users\dipan\Documents\Development\Salesforce\LWC\LWC Labs> sfdx force:org:create -a LWCScratchOrg1 -d 30 -f config/project-scratch-def.json -s
Creates a scratch org or a sandbox org using the values specified in a configuration file or key=value pairs that you specify on the command line. Values specified on the command line override values in the configuration file. This release contains a beta version of the sandbox CLI operations, which means it’s a high-quality feature with known limitations.
sfdx force:org:create[–json][–loglevel LOGLEVEL][-v TARGETDEVHUBUSERNAME][-u TARGETUSERNAME][–apiversion APIVERSION][-t TYPE][-f DEFINITIONFILE][-n][-c][-i CLIENTID][-s][-a SETALIAS][-w WAIT][-d DURATIONDAYS]
Tips: The duration of the scratch org, in days. Valid values are from 1-30. The default is 7 days.
Tips: while creating a scratch org or a sandbox. When creating scratch orgs, —targetdevhubusername (-v) must be a Dev Hub org. When creating sandboxes, the –targetusername (-u) must be a production org with sandbox licenses. The —type (-t) is required if creating a sandbox.
Create a class:
Push the class to scratch org: