Get Started With Salesforce DX (Salesforce Developer Experience)
Get Started With Salesforce DX : Introduction and basics of Salesforce DX (Salesforce Developer Experience)
Salesforce DX provides development teams with an integrated, end-to-end lifecycle for high-performance agile development – designed to be open and flexible so you can build together with tools you love.
But first question that arises is why we need Salesforce DX?
We already have tools like force.com IDE, changeset, metadata API, force.com Migration tool using ant.
But problem with current system without DX is that, source of truth is sandbox or your production. With Salesforce DX source of truth is always Version Control System(VCS) or Source Code Management(SCM). Developers can use any tools like Git or SVN.
Although VCS or SCM like git or SVN can be used without Salesforce DX as well. But with Salesforce DX, using these tools becomes easier.
This is not only advantage of using Salesforce DX. There are other advantages as well:
- Source of truth: Use scratch orgs during development and with CI tools.
- Scratch Orgs: Use scratch orgs during development and with CI tools.
- Source Sync: Sync all packageable source/metadata into and out of scratch orgs.
- Salesforce CLI: Use the Salesforce CLI to interact with scratch orgs, source sync, Heroku, and Salesforce other services.
- Test Runner: The ability to define test profiles to be executed by developers (i.e. interactively invoked via CLI) and CI processes.
- Continuous Integration: The ability to use SFDX innovations with any CI process (i.e. TeamCity, Jenkins, Travis CI, or Heroku CI).
- Force.com IDE: The ability to use the new Force.com IDE.
What is Scratch Org?
Salesforce DX can be enabled for any Salesforce instance and they are known as Developer Hub. One Developer Hub can have multiple Scratch Orgs. A scratch org is a dedicated, configurable, and short-term Salesforce environment that you can quickly spin up when starting a new project, a new feature branch, or a feature test.It can be used by developers to perform quick proof of concept or build and test. Scratch org can be destroyed easily once its no longer required.
Following are steps to use Salesforce DX:
- Need Dev Hub Org:
Get your own 30-day Dev Hub Trial Org
https://developer.salesforce.com/promotions/orgs/dx-signup
OR
Enable the Dev Hub in Your Org - Install sfdxcli :
https://developer.salesforce.com/tools/sfdxcli - Install IDE 2 :
https://developer.salesforce.com/docs/atlas.en-us.sfdx_ide2.meta/sfdx_ide2/sfdx_ide2_get_started_download_install.htmNext Step is either Clone repository or we can Create skeleton project
- Clone Repository:
In Salesforce DX, source of truth is source control. so we need a repository for demo.
https://github.com/forcedotcom/sfdx-simplegit clone https://github.com/forcedotcom/sfdx-simple cd sfdx-simple
Or we can use following repository
https://github.com/forcedotcom/sfdx-dreamhouseOR
- Creating skeleton project
sfdx force:project:create --projectname myproject --defaultpackagedir myapp OR sfdx force:project:create -n myproject -p myapp
- Authorize Salesforce DX to login to Developer Hub Org
sfdx force:auth:web:login --setdefaultdevhubusername --setalias ankushDevHub OR sfdx force:auth:web:login -d -a ankushDevHub
- Creating Scratch Org
Need to edit project-scratch-def.json file with this content{ "country": "US", "edition": "Developer", "orgPreferences": { "enabled": [ "S1DesktopEnabled" ], "disabled": [] }, "orgName": "AnkushDureja", "adminEmail": "dureja.ankush90@gmail.com" }
Run following in CLI:
sfdx force:org:create --setdefaultusername -f config/project-scratch-def.json --setalias ankushfirst_scratch
Deleting scratch org:
sfdx force:org:delete OR sfdx force:org:delete -u ankushfirst_scratch
- Getting list of all existing Org
sfdx force:org:list
- Open Salesforce Org from sfdx
sfdx force:org:open OR sfdx force:org:open -u org_alias
- Password for scratch Org
ssfdx force:user:password:generate
- Moving code to Scratch Org
Edit following file:
sfdx-project.json{ "packageDirectories": [ { "path": "force-app" } ], "namespace": "", "sourceApiVersion": "39.0" }
Now use following commands:
sfdx force:source:push OR sfdx force:source:push --targetusername myscratchorg
- Get metadata changes from Scratch Org or Pull changes
sfdx force:source:pull OR sfdx force:source:pull -u org_alias
- Running Test classes using Salesforce DX
sfdx force:apex:test:run
Above command will return job Id, use that ID and run next command for status
sfdx force:apex:test:report -i JOBID_FROM_ABOVE_COMMAND
- Import and Export Records using Salesforce DX
We don’t need Developer Hub or Scratch Orgs to use Salesforce DX for import and export.
Exporting Data:sfdx force:data:tree:export -q "SELECT Id,Name FROM Account limit 10" -d ./mydata -u ankushDevHub
Import Data:
sfdx force:data:tree:import -f mydata/Account.json -u ankushfirst_scratch
- Help for any command
sfdx force:org:open -h OR sfdx force:org:open --help
Recent Comments