This is the first part of the salesforce DX introduction series. Salesforce DX is a combination of the set of tools like Salesforce DX CLI and IDE’s like Force.com IDE 2 or Visual code Studio and set of new features that affect the app development lifecycle.Salesforce Developer Experience (DX) is a new way to manage and develop apps on the Lightning Platform across their entire life cycle. It brings together the best of the Lightning Platform to enable source-driven development, team collaboration with governance, and new levels of agility for custom app development on Salesforce.Below are the few highlights of salesforce DX
Powerful command-line interface (CLI) to manage development lifecycle
Flexible and configurable scratch org which are easy to create and dispose
You can use any IDE or text editor
The ability to apply best practices to software development.
You can use tools to build Continuous Integration and Continuous Delivery.
You can build and test the application independently into small packages
Packaging supports for agile distribution
Enable Second-Generation Packaging (2GP) in your org so you can develop 2GP packages.
The below image shows the life cycle of applications development management with Salesforce DX.
Salesforce DX aims to remodel your development process by providing the major improvements required to manage a complex org with multiple development teams. To realize these improvements, Salesforce DX shifts the model of development from a monolithic org-based development process to a modular artifact-based development process. An artifact is a group of related code and customizations. An artifact can be tested independently from other components in your Org. An artifact should be able to be released independently as well. The metadata components within an artifact can only live in one artifact at a time. The modular artifact-based development gives you more flexibility in managing your teams and releases. You can assign teams to own a particular artifact. Development teams can develop separately and build toward a release of the artifact, and not a release of updates to the Org. With this agile model, you can have more frequent, independent releases, as you can see in the development, build, and deploy flow.
Dev Hub is the First point to start using salesforce DX. Enable Dev Hub in your org so you can create and manage scratch org from the command line and Lightning Experience. Dev Hub comprises objects with permissions that allow admins to control the level of access available to a user and an Org. You can enable dev from the salesforce development menu under setup.
Once you enabled you can start using the CLI to login into the Dev Hub
Salesforce DX is come up with the powerful CLI to interact with application lifecycle. Use the Salesforce command-line interface (CLI) for most Salesforce DX tasks. These tasks include authorizing a Dev Hub org, creating a scratch org, synchronizing source code between your scratch org and VCS, and running tests and other.
You can use CLI in few of the cases
Login to the Dev Hub and Create a Scratch Org.
Sync Source from and to the Scratch org and Local code base
Import and export data setup
Integrate version control and Continuous Integration and Continuous delivery models.
Scratch org short time development org which can be used to develop or build any application on Salesforce. The scratch org is a source-driven and disposable deployment of Salesforce code and metadata. A scratch org is fully configurable, allowing developers to emulate different Salesforce editions with different features and preferences. And you can share the scratch org configuration file with other team members, so you all have the same basic org in which to do your development.Scratch org drive developer productivity and collaboration during the development process and facilitate automated testing and continuous integration. You can use the CLI or IDE to open your scratch org in a browser without logging in. You might 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
You can spin the scratch org from the CLI by using the following command
The scratch org definition file(project-scratch-def.json) is a blueprint for a scratch org. It mimics the shape of an org that you use in the development lifecycle, such as the sandbox, packaging, or production.
Edition—The Salesforce edition of the scratch org, such as Developer, Enterprise, Group, or Professional.
Add-on features—Functionality that is not included by default in an edition, such as multi-currency.
Org preferences—Org and feature settings used to configure Salesforce products, such as Chatter and Communities.
Setting up different scratch org definition files allows you to easily create scratch org with different shapes for testing. For example, you can turn Chatter on or off in a scratch org by setting the ChatterEnabled org preference in the definition file. If you want a scratch org with sample data and metadata like you’re used to, we have an option for that: hasSampleData as shown below.
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. If you don’t indicate an output directory, the project directory is created in the current location. You can also specify the default package directory to target when syncing source to and from the scratch org. If you don’t indicate a default package directory, this command creates a default package directory, force-app with the project folder name as DXLearning.
The force:project: create command generates these samples configuration files to get you started as shown below.
The project configuration file sfdx-project.json indicates that the directory is a Salesforce DX project. The configuration file contains project information and facilitates the authentication of scratch org and the creation of second-generation packages. It also tells Salesforce DX where to put files when syncing between the project and scratch org.