Salesforce DX Absolute Beginner ( Part 3 Of 7 )

In this third part of the salesforce DX series, I am going to show how to set up salesforce dx project from the beginning. I am assuming that you are implementing the new application or project from the beginning. So there is no salesforce metadata is configured. Follow this basic workflow when you are starting the application from the beginning

1. Login into Dev Hub from CLI 

First, you need to login to the Dev Hub from the CLI to start the new project.
 Run the force:auth:web:login CLI command. If you are authorizing a Dev Hub org, use the —setdefaultdevhubusername parameter if you want the Dev Hub org to be the default for commands that accept the —targetdevhubusername parameter.
sfdx force:auth:web:login --setdefaultdevhubusername --setalias my-sfdc-hub-org

After Successful login into the Dev Hub, you can see the success message into the CLI as shown below.

 2. Create an SFDX Project

A Salesforce DX project has a specific structure and a configuration file that identifies the directory as a Salesforce DX project.Use the force:project:create command to create a skeleton project structure for your Salesforce DX project. The force:project:create command generates these samples configuration files to get you started.

sfdx force:project:create --projectname DXLearning

 The force:project:create command generates these samples as shown below.
 3. Create a Scratch Org for Development

You can create scratch orgs for different functions, such as for feature development, for development of packages that contain a namespace, or for user acceptance testing and much other use cases. Use force:org: create to create a scratch orgs .

sfdx force:org:create -f config/project-scratch-def.json --setdefaultusername --setalias my-sfdc-scratch-org

4.Open scratch Org
 You can open scratch org by running force:org:open command from the CLI. After login into the scratch org, you can make any configuration changes. Later you can pull them into local folders.
sfdx force:org:open


sfdx force:org:open -u <username/alias>

5. Push and Pull the code

Go and create some couple of objects in the salesforce scratch org after that we will pull into the local salesforce dx by using the pull commands. You can pull configuration and code from scratch org by using force:source:pull command.
sfdx force:source:pull

Create an Apex Class from the CLI with below command
sfdx force:apex:class:create  --classname CustomerApexController --template DefaultApexClass --outputdir force-app/main/default/classes/

Make some changes to the code as shown below.
Now push the changes to Scratch org from the local development with force:source:push command
sfdx force:source:push
After successfully push, you can able to see the changes in the scratch org
Here are the overall highlights of this post before starting part 4.
  •  Login to the Dev Hub
  • Create a Scratch Org
  • Create Salesforce DX Project
  • Pull changes into Salesforce DX project from the scratch org
  • Make changes locally and push into scratch org.