Goal of this post is to setup your SFDX environment and perform below activities,
(for my case it is sfdx force:org:open -u ArunSFDX Demo)
- DevHub setup,
- Local workspace/project creation,
- Scratch Org creation,
- Pereform PUSH/PULL operation (deploy/retrieve) etc.
Step by step perform the below action items.
1. First you have to install sfdxcli. Download it from https://developer.salesforce.com/tools/sfdxcli (I have download here). Then install it in your machine and set your environment variable for your install sfdxcli.
2. Now open command prompt and run below command to check is it working properly.
3. Now create a folder where you want to setup your local repository for sfdx operation. For my case say it under"D:\Assignments\Salesforce DX".
4. Now open CLI and change the directory location to above location using below command,
5. Now setup your DevHub org from where you want to create scratch Orgs. To setup an Org as DevHub run the below command in your CLI.
6. It takes few seconds and browser window will open. Put your user name and password and after successful login in browser it will show below successful message in CLI.
1. First you have to install sfdxcli. Download it from https://developer.salesforce.com/tools/sfdxcli (I have download here). Then install it in your machine and set your environment variable for your install sfdxcli.
2. Now open command prompt and run below command to check is it working properly.
sfdx -v
3. Now create a folder where you want to setup your local repository for sfdx operation. For my case say it under"D:\Assignments\Salesforce DX".
4. Now open CLI and change the directory location to above location using below command,
cd D:\Assignments\Salesforce DX
5. Now setup your DevHub org from where you want to create scratch Orgs. To setup an Org as DevHub run the below command in your CLI.
sfdx force:auth:web:login --setdefaultdevhubusername --setalias my-devhub-org
6. It takes few seconds and browser window will open. Put your user name and password and after successful login in browser it will show below successful message in CLI.
7. If you already login in your DevHub org, then go to setup and search for "Dev Hub" and then enabled Dev Hub. Otherwise you will get error while try to create scratch org (explain below).
8. Now your dev hub is ready and you are ready to create your scratch org. But before create a scratch org first create local workspace/project. And it is the location where you push or pull your source code to your scratch org or from your scratch org respectively.
Now run the below command to create a wrokspace/project in your local directory,
sfdx force:project:create --projectname MyFirstSFDXProject
So, a new project will be create named as "MyFirstSFDXProject" under "D:\Assignments\Salesforce DX" directory.
9. Now open the folder "D:\Assignments\Salesforce
DX\MyFirstSFDXProject\config” there is a file named as "project-scratch-def.json". This json file contains scratch org information. So, you can edit this file to setup your scratch org name, edition etc.
{ "orgName": "ArunSFDX Demo", "edition": "Developer", "orgPreferences" : { "enabled": ["S1DesktopEnabled"] } }
10. Run the command in CLI to change the directory to your project directory which is created in point 8.
cd MyFirstSFDXProject
11. Now check your Dev Hub connection and list of scratch orgs related to this dev hub. Currently we don't have any scratch org. Run the below command for checking,
sfdx force:org:list
12. Create
Scratch Org (Use the above JSON as mention in point 9) and run the below command. Here I have given my scratch org alias name as "MyScratchOrg1".
sfdx force:org:create --setdefaultusername -f config/project-scratch-def.json --setalias MyScratchOrg1
Note: If you miss to enable Dev Hub as mentioned in point 7, then you will get the below error. So, enable your dev hub as mentioned point 7 and run the command again.
13. If the above command run successfully then CLI will show your scratch org name.
Response message:
Successfully created scratch org:
00DN0000000REujMAG, username: test-f2bwflahpmax@example.com
14. Now like point 11, you can check the dev hub connection and it's scratch org list. Currently we have one scratch org. Run the same command as mentioned in point 11.
sfdx force:org:list
15. Open your scratch org by below command (No
password is here).
sfdx force:org:open
or
sfdx force:org:open -u org_alias
(for my case it is sfdx force:org:open -u ArunSFDX Demo)
System
will automatically open the scratch Org in your default browser or you can open
the ORG by copy paste the displaying URL in CLI.
16. You can generate
password for your scratch org.
sfdx force:user:password:generate
17. You
can see the password / org details again by running below command.
sfdx force:user:display -u scratch_org_user_name
For me it like,
sfdx
force:user:display -u test-f2bwflahpmax@example.com
18. Check
Company Information and it is same as you mentioned in your JSON
19. As
this scratch org is developer org so the storage limit is low and you can check
it from “System Overview”.
20. Now
try to deploy some source code in the scratch org.
- Open your project folder (D:\Assignments\Salesforce DX\MyFirstSFDXProject) and here you get a json file named as “sfdx-project.json”.
- Open the json file and there you get the source directory folder path, where you put your source code to deploy.
{ "packageDirectories": [ { "path": "force-app", "default": true } ], "namespace": "", "sfdcLoginUrl": "https://login.salesforce.com", "sourceApiVersion": "44.0" }
- Suppose I want to deploy some class. So create “Classes” folder and here put your classes and their metadata. Folder and file structure is same as used on the time of ant deployment and only difference is here being no package.xml is required.
- For our case say, I want to deploy “ToolBean.cls”.
- Now use below push command for deployment.
sfdx force:source:push
- Check Org for this deployment,
- Now suppose I have created another class (ArunSFDXDemoClass.cls) and a lightning component (ArunSFDXDemoComponent.cmp) and also modify existing class (ToolBean.cls) in scratch org and finally I want to pull it from scratch Org.
- Now run the below command to pull the above new and modified source code.
- Before pull
sfdx force:source:pull
- After pull
21. Once you complete your work then logout from org. Below are the logout command,
sfdx force:auth:logout -u test-f2bwflahpmax@example.com