Understanding Salesforce DX
Salesforce DX is a set of tools and features that improve the efficiency of development during the application lifecycle. It addresses common challenges faced by developers, allowing them to manage the source of truth and lifecycle for the org. With its accessible and useful tools, development teams can easily work with command line interfaces (CLIs) or integrated development environments (IDEs).
Developers use sandboxes as part of their development process in Salesforce to create and test changes. This can sometimes lead to issues with a moving “source of truth” that may not be in the same sandbox. Salesforce DX allows for a new way to define the source of truth using centralized source control systems in what is called source driven development. While this new environment does not eliminate conflicts, it moves some of the more challenging aspects of development into source control systems to create a more efficient process. Source driven development allows for greater visibility of present versions and history.
Salesforce DX has additional features to simplify the management of releases and orgs called unlocked packages. These unlocked packages provide a replicable and trackable method to introduce and manage org changes. Whether you are an independent developer or part of a team, Salesforce DX offers an assortment of tools to choose from. Agile development is supported by best-in-class command line interface, text editors, IDE, CLI, and many more. The design is open and flexible, driving continuous integration and delivery. Ultimately, Salesforce DX is a way for developers to mange and develop apps throughout their entire lifecycle.
The Salesforce DX Toolset
Salesforce DX was designed to increase productivity with an environment that lets developers work collaboratively on projects within the Salesforce platform. Salesforce DX creates an open environment that makes development easy while maintaining a focus on quality and predictability in the standardized development lifecycle. It has been described as the best of the Force.com and Heroku developer experiences, allowing developers to continuously build and deliver together.
Salesforce DX allows developers to decided which tools to use. It could be a particular text editor in conjunction with the Salesforce CLI or Salesforce Extensions for VS Code. Users can also select which VCS to use. When using Salesforce Extensions for VS Code, there are several extensions to facilitate developing with Salesforce DX.
Salesforce CLI is a single command-line interface that is used in all Salesforce DX features. It reduces development time across the entire Salesforce Platform. Built around open APIs, the CLI easily integrates into existing developer workflows. It can be used to aggregate development tools, synchronize source, manage orgs and data, execute tests, and install packages. CLI is the best interface for interactive command line development, continuous integration, and continuous delivery, and automation. This consolidated interface for many APIs is the driver for Visual Studio Code extensions. It is also the driver of new third-party features like Illuminated Cloud and the Welkin Suite.
Figure 1- Source: https://developer.salesforce.com/blogs/2018/02/getting-started-salesforce-dx-part-2-5.html
When you install the Salesforce CLI and run Salesforce DX commands, you will need to authenticate to a Dev Hub. This functionality creates a manageable environment called scratch org. The Dev Hub functionality is easy to turn on from the Production org, but remember that this change cannot be undone. With the Dev Hub capabilities, you will be able to create user records and permission sets for your team members.
The scratch org is a disposable, source-driven deployment of code and metadata. Because it is fully configurable, developers can emulate different Salesforce editions selecting specific features necessary for a particular project. It is easy to share the scratch org file with your team so that everyone is working with the same basic org for development. The scratch org is a source-driven, fully configurable, and entirely disposable environment that is optimized for development and automated quality testing. Built from source, scratch orgs are simple to create, use, and delete using the CLI when finished.
In source-driven development, the source is organized into artifacts based on group features or customizations that are delivered together. Salesforce DX incorporates the artifact-based approach to organizing the source. There is the ability to shift the source of truth from the org to a version control system (VCS), along with the use of popular collaboration technologies including Git and other test-build automation tools.
Open and Standard Tools
Salesforce DX gives developers the option of building with open and standard tools including Git, VS Code, Selenium, Eclipse, and others. Built around a command-line interface and open APIs, it has the flexibility to allow building with any tools based on open-source standards.
Using Salesforce DX, it is possible to organize metadata and distribute apps while adopting a CLI-centric source approach to automate and manage the entire application lifecycle. The new packaging features offer an organization system for metadata along with a distribution system for apps. These managed packages take advantage of the new Salesforce DX tools including Scratch Orgs, CLI, and VS Code, all to improve the development experience within the Salesforce platform.
Figure 3 – Source: https://developer.salesforce.com/blogs/2018/02/getting-started-salesforce-dx-part-2-5.html
Salesforce DX has a lot to offer with its new approach. The new tooling will support more metadata types and offer higher levels of interface for a development experience that is more accessible to the community. Whether developers adopt some or all of this new technology, there are tools that can optimize the development process at every stage. Teams can move into full source-driven development or simply adopt a new version control strategy that allows them to work together more effectively. Salesforce had endless options, and it’s up to you how to proceed for the most effective and efficient lifecycle management.
Salesforce DX uses the executable command “sfdx” for the Salesforce CLI. However, this does not mean that the Salesforce CLI is limited to use with only Salesforce DX projects. Using this command line interface allows developers to run numerous tasks in the Salesforce environment. The functionality is tailored to Salesforce DX, but it is available for use across any type of org.
The CLI does require certain variables in order to communicate to the different orgs. Developers can create global or local variables, but keep in mind that local variables take precedence over global variables. While the CLI is a powerful tool, it does not handle complex data operations or create ContentVersion records.
To get past this, the Anonymous Apex script is what you will need. This script creates local files with Apex code that is executed using the Salesforce CLI. It can be used to read local files and create ContentVersion records in the scratch org with the file contents. This eliminates the need to manually upload files on new scratch orgs.
Advantages of Salesforce DX
Salesforce DX facilitates how developers create and manage Salesforce apps throughout the development lifecycle. This platform was built to enhance productivity levels with better control and improved collaboration. The Salesforce platform does not have a built-in version control system which is why DX was introduced. With the version control feature, developers can manage the auditing and testing process more efficiently.
Figure 4 – Source: https://developer.salesforce.com/blogs/2018/02/getting-started-salesforce-dx-part-5-5.html
By blending automatic functions and manual actions, Salesforce DX enables developers to build and release updated features in a short span of time with minimal risk. Salesforce DX improves developer productivity through increased flexibility with additional tool offerings to create simple workflows.
Salesforce DX gives you agile development methodologies allowing faster, more efficient development. The collaborative development environment has the source version control needed for continuous development.
Salesforce DX works best with source driven development. By moving your project resources to a Version Control System (VCS), you will be able to track content revisions and take advantage of the collaboration capabilities. With this automation, you can implement the continuous integration features.
The CI tool allows you to run both unit and integration tests. Unit tests are based on small units of code without a third-party system. An integration test is one that guarantees functional code in an external system. Automating these two tests can reduce the risk of regressions that are sometimes introduced through code modifications. The CI tool is always running to clean the testing environment regardless of the outcome. This prevents running into an active scratch org limit issue. With Salesforce DX, deleting test scratch orgs can be completed with a single command.
Continuous deployment automatically sends content into production after the integration testing is complete. This can shorten the feedback loop and eliminates the need for release dates while allowing business requirements to dictate the release cycle. This functionality can be leveraged in beta testing to determine production outcomes.
Figure 6 – Source: https://developer.salesforce.com/blogs/2018/02/getting-started-salesforce-dx-part-5-5.html
Deciding If You Need Salesforce DX
Salesforce DX is an integrated, end-to-end lifecycle tool that allows for agile development. Its flexibility allows developers to work together with an assortment of tools for improved efficiency. Although Salesforce provides a sufficient cloud platform, they are dedicated to improving the developer experience which is what lead to the creation of Salesforce DX.
Improving the lifecycle environment means having the right set of collaborative tools that provide cloud governance, compliance, and security. Salesforce DX incorporates the standard tools but gives developers access to many more. The most significant new features to improve developer workflow are new APIs, the environment hub, scratch orgs, and the refreshed command line interface.
The decision to incorporate Salesforce DX depends on the needs and capabilities of your team. The Salesforce DX tools do not use a point-and-click interface, which can be a challenge for some. These tools are available within a CLI or IDE, which is a skillset that some teams do not have. If you are willing to invest the time into building these skills, the tools in Salesforce DX will improve the efficiency and collaboration capabilities of the team, resulting in an increased output.