Salesforce Developer Experience
Salesforce Developer Experience
Developer Experience
Table of Contents
1. Introduction 1
2. Salesforce DX - An Overview 5
3.5 Push the source from your project to the scratch org 16
3.7 Pull the source to keep your project and scratch org in sync 18
3.12 Sync up 20
5. Challenges 22
6. Conclusion 23
7. About DemandBlue 23
1 Salesforce Developer Experience
1. Introduction
Salesforce Developer Experience (DX) is a brand new way to develop and manage apps on the
Lightning Platform across the entire life cycle. It combines 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.
Why
To improve team development and collaboration, it facilitates automated testing and continuous
integration, and makes the release cycle more efficient and agile.
Salesforce DX is much more than just a new set of tools. It provides an alternative to change set
development and shifts the source of truth from the org to version control system (VCS). It shifts our
development focus from org development to package development.
It needed some manual steps like creating a new salesforce org, maintaining a script that
can create a package.xml from source code and maintaining ANT script to deploy code to
the respective. Of course many organizations have automated this process, however certain
manual steps including enabling chatter, enabling Person Accounts, creating multi-currency
instance, Enabling Service Cloud and so on. Currently, Salesforce Developer Experience
supports automatic enablement of some of these features and org preferences. All you need
to do is maintain a project-scratch-def.json file in your source control for the project.
Doing this on the platform has been quite challenging, predominantly because you need
skilled engineers familiar with force.com APIs and migration tools to build and maintain this
and with ever-changing metadata with every release this has been challenging.
4 Automated Test Runs For Lightning Components and Apex Unit Tests
Automating unit tests can certainly help quality and ensure smoother application packaging
and deployment. You can configure your Continuous Integration to automatically run your
apex unit tests and tests for lightning components
DX makes it one step easier by writing a query and using export command to get a JSON file
and then seamlessly import the JSON file back to another scratch org. You might be thinking
about IDs and relationships – if you need not do excel VLOOKUP any more.
4 Salesforce Developer Experience
For as long as there are relationships between objects and you have compiled query, it is
straight forward. One thing that has to be explored is the limit of data json file that can be
exported and imported.
The above will export Account and associated Contacts and then import using the CLI again
using the command below
(Note that while packaging salesforce looks after namespacing for most of the components
but for the rest we handled it by appending namespace dynamically).
5 Salesforce Developer Experience
With Salesforce DX, you could have multiple scratch orgs with the same namespace and
therefore what this would mean is if we are 100% confident and namespace is decided
upfront we can hardcode it in the code. This makes building lightning components easier
without having to worry about workarounds. However, we would still caution and recommend
you to keep the code namespace independent.
2. Salesforce DX - An Overview
Salesforce Developer Experience (DX) is a brand new way to manage and develop apps on the
Lightning Platform across the entire life cycle. It combines 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.
• With Salesforce DX, we can use the developer tools you already know.
• The ability to apply best practices to software development. Source code and metadata
exist outside the org and provide more agility to develop Salesforce apps in a team
enviroment Instead of the org, version control system is the source of truth.
• With a powerful command-line interface (CLI) it removes the complexity of working with
your Salesforce org for development, continuous integration, and delivery.
• Flexible and configurable scratch orgs you build for development and automated
environments. This type of org makes it easier to build your apps and packages.
• We can use any IDE or text editor you want with the CLI and externalized source.
• Salesforce Extensions for VS Code to accelerate app development. These tools provide
features for working with scratch orgs, Apex, Lightning components, and Visualforce.
(or)
Get your own 30-day Dev Hub Trial Org at:
https://developer.salesforce.com/promotions/orgs/dx-signup
htm
(or)
Get your own 30-day Dev Hub Trial Org at:
https://developer.salesforce.com/promotions/orgs/dx-signup
requirements.
Go to:
https://developer.salesforce.com/tools/sfdxcli and get the latest version.
7 Salesforce Developer Experience
For information about installing Salesforce CLI, see the Salesforce DX Setup Guide.
Though scratch orgs are meant to be disposable, the scratch org configuration files contain
the real brawn. Through the configuration file, we can configure the scratch org with different
Salesforce editions and with just the features and settings we want. And we can share the
scratch org configuration file with other team members. That way, we all will have the same
basic org in which we can develop.
• A Dev Hub provides us the ability to create and manage scratch orgs.
• Scratch orgs are temporary Salesforce environments where we can do the bulk of
development work in this new source-driven development paradigm.
• We can use the CLI or Salesforce Extensions for VS Code to open our scratch org in a
browser without logging in
• If multiple users changing the same files make conflicts and failing to resolve these
effectively can yield corrupt XML
• It’s not uncommon for these items to contain a variety of different changes according to
different features in active development in a particular org - this means when pushing
changes, developers need to edit these XML files by hand to incorporate only the specific
changes they want to push in that deployment or commit
9 Salesforce Developer Experience
To overcome this-
• DX uses a slightly modified folder structure that breaks up some of the larger, more
complex metadata into subcomponents, providing a good workaround to these problems.
• It’s worth noting, however, that because it uses the same underlying APIs there are still
problems this mechanism doesn’t address.
• It also comes with the added benefit of loosening some of the restrictions on folder
structure, allowing you to introduce subfolders to organize your Apex classes
Metadata Coverage
https://developer.salesforce.com/docs/atlas.en-us.218.0.sfdx_dev.meta/sfdx_dev/sfdx_dev_supported_mdapi_types.
htm
Salesforce has already mentioned that the Salesforce Extensions for VS Code are the future of
Salesforce development. They have dedicated their resources to make this the best and most
enjoyable desktop editor for Salesforce developers. With this focus on Visual Studio Code, Salesforce
is moving away from our support of Eclipse. While the Force.com IDE will be supported and will
receive some updates in the near future, the updates will focus mainly on compatibility (and of
course, security if needed). Salesforce will not be adding any new major features to the Force.com
IDE and we will eventually deprecate it entirely.
2 Install it
10 Salesforce Developer Experience
• Access to Apex Language Server for syntax highlighting and code completion
2 On the left toolbar, click the Extensions icon (the last icon down)
11 Salesforce Developer Experience
2.6.1 Advantage
Use packaging to take advantage of these helpful features:
• The Salesforce CLI provides commands for the entire application life cycle so you can work
efficiently with your packages, scratch orgs, and development processes
• Options for enterprise customers to organize and deploy metadata to production orgs
• Multiple packages per namespace, so you can better organize your source and easily share
Apex code. You can use public Apex classes across packages rather than global Apex classes
12 Salesforce Developer Experience
2.6.2 Limitations
Unable to Specify a Patch Version
Description:
The four-part package edition number includes a patch segment, known as major.minor.patch.build. However, you
cannot create a patch for a second-generation package. Package creation fails if you set a patch number in the
Workaround:
Always set the patch segment of the version number, to 0. For example, 1.2.0.1 is valid but 1.2.1.1 is not.
Protected Custom Metadata and Custom Settings are Visible to Developers in a Scratch
Org If Installed Packages Share a Namespace
Description:
Use caution when you store secrets in your second-generation packages using protected custom metadata or
protected custom settings. You can create multiple second-generation packages with the same namespace.
However, when you install these packages in a scratch org, these secrets are visible to any of your developers that
are working in a scratch org with a shared namespace. In the future, we might add a “package-protected” keyword
Workaround:
None
Source:
https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_dev2gp.htm
13 Salesforce Developer Experience
The CLI combines capabilities from across several Salesforce APIs, such as Metadata API, Tooling
API, and Data (SOAP) API. It also supports the functionality of Ant Migration Tool that allows for
scripting of metadata tasks. With the new and improved CLI, all our development tasks from all the
important APIs are available in one place. We can script everything from the creation of orgs to the
import and export of data–everything required to manage the complete development life cycle.
NOTE
Login must be a valid login to your Dev/Sandbox Org and with Admin permissions
https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth.htm
• Create a scratch org for development using a scratch org definition file
The scratch org definition defines the org edition, features, org preferences, and some other
options.
sfdx force:org:create -f project-scratch-def.json
• Specify scratch org definition values on the command line using key=value pairs
ssfdx force:org:create [email protected] edition=Developer \
[email protected]
• Create a scratch org for user acceptance testing or to test installations of packages
In this case, you don’t want to create a scratch org with a namespace. You can use this
command to override the namespace value in the scratch org definition file.
sfdx force:org:create -f project-scratch-def.json --nonamespac
15 Salesforce Developer Experience
• Specify the scratch org’s duration, which indicates when the scratch org expires (in days).
The default is 7 days. Valid values are from 1-30.
sfdx force:org:create -f config/project-scratch-def.json --durationdays 30
sfdx force:org:create -f config/project-scratch-def.json -d 3
• Standard output displays two important pieces of information: the org ID and the username.
• username: [email protected]
3.5 Push the source from your project to the scratch org
2 To push changed source to a scratch org that’s not the default, you can indicate it by
its username or alias :
sfdx force:source:push --targetusername [email protected]
sfdx force:source:push -u [email protected]
sfdx force:source:push -u MyGroovyScratchOrg
org.htm
17 Salesforce Developer Experience
apex:class:create
apex:trigger:create
lightning:app:create
lightning:component:create
lightning:event:create
lightning:interface:create
lightning:test:create
visualforce:component:create
visualforce:page:create
Option Description
-d, --outputdir The directory for saving the created files. If you don’t indicate a directory,
your source is added to the current folder.
-t, --template Template used for the file creation
If you want to generate a URL that loads the .flexipage-meta.xml file in Lightning App Builder but
does not launch your browser, use the --urlonly flag.
sfdx force:source:open -f Property_Record_Page.flexipage-meta.xml -r
https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_develop.htm
18 Salesforce Developer Experience
3.7 Pull the source to keep your project and scratch org in sync.
After you do an initial push, Salesforce DX tracks the changes between your local file system and
your scratch org. If you change your scratch org, you usually want to pull those changes to your
local project to keep both in sync.
During development, you change files locally in your file system and change the scratch org us-
ing the builders and editors that Salesforce supplies. Usually, these changes don’t cause a conflict
and involve unique files.
By default, only changed source is synced back to your project.
https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_pull_md_from_scratch_
org.htm
2. This command runs all Apex tests in the scratch org asynchronously and then outputs a job
ID. Pass the ID to the force:apex:test:report command to view the results. The results in
clude the outcome of individual tests, how long each test ran, and the overall pass and fail
rate.
sfdx force:apex:test:report --testrunid 7074C00000988ax
19 Salesforce Developer Experience
4. Use the --synchronous parameter to run tests from a single class synchronously. The com
mand waits to display the test results until all tests have completed.
sfdx force:apex:test:run --synchronous --classnames TestA
5. Use parameters to list the test classes or suites to run, specify the output format, view code
coverage results, and more. For example, the following command runs the TestA and TestB
test classes, provides results in Test Anything Protocol (TAP) format, and requests code
coverage results.
sfdx force:apex:test:run --classnames TestA,TestB --resultformat tap --codecoverage
6. Use the --tests parameter to run specific test methods using the standard notation Class.
method. If you are testing a managed package, use namespace.Class.method. If you spec
ify a test class without a method, the command runs all methods in the class. This example
shows how to run two methods in the TestA class and all methods in the TestB class.
sfdx force:apex:test:run --tests TestA.excitingMethod,TestA.boringMethod,TestB
Export package.xml file into the temporary directory. Type the commands below in the root folder
of your Salesforce DX project:
Note:
If the project source location contains empty spaces, then ensure that you enclose the complete
path within double quotes (“”).
Unzip the unpackaged.zip file that is created from the above command and optionally delete the
unpackaged.zip file.
20 Salesforce Developer Experience
3.12 Sync up
Sync the local version with the version deployed to Scratch Org for every change and test the
changes on the Scratch Org by repeating the above steps.
Once the testing is completed, we need to convert the source from Salesforce DX format to the
Metadata API format. This is done by running the following command:
sfdx force:source:convert --outputdir {OUTPUT DIRECTORY HERE}
Copy the modified metadata files from this output location to the actual source location where the
metadata files are downloaded from Dev/Sandbox Org to deploy the files to the server.
• Keeping things simple not just improves development speed, it also makes maintenance
and training much easier
• Follow the same development flow for both new features and bug fixes
• All changes should be deployed out to your testing environments as soon as possible after
merging
21 Salesforce Developer Experience
• Include minimum viable number of changes in one branch and not more
• The longer a branch exists without getting merged, the greater risk for merge conflicts and
deployment challenges
• Multi-Browser Testing
• Stores all source for your packages in a source control repository, where the source of truth
is maintained. Being a single ‘source of truth’ for the team.
• Build scratch (development) orgs from that source, so you can work specifically on your
package
• It provides change tracking features to monitor what you’ve created, updated, and deleted
in the development org and makes it easy to maintain and deploy different versions of code
across test, staging and production environments
• It is easy to pull modified source down to your file system and check it into your VCS
• Maintains a full audit trail for every stage of the development cycle.
• Facilitating collaboration and code review
22 Salesforce Developer Experience
5. Challenges
DevOps, as applied to Salesforce.com development is different. These are common challenges in
release management and software development
• Testing suffers when environments differ that result in defects and production issues
• Loss of confidence to test results when environments are different that lead to defects and
re-work
• Manual deployments are a key bottleneck across projects and test phases
• Future Releases that are built on an old Production refresh requires added testing and de
ployment time
Maintenance issues
• Go-Live is challenging with hundreds of manual steps
There are few challenges that DevOps teams need to consider with the Salesforce deployment
model:
• Comprehending how to merge and deploy code from one Salesforce Org to another.
• The Metadata API does not support rolling-back once the API call has been completed suc-
cessfully.
• Not all elements can be deployed using Metadata API, because either Salesforce has not
yet added those items to the Metadata API or they are configuration changes unique to each
Org.
23 Salesforce Developer Experience
6. Conclusion
Salesforce Developer Experience is a great step and will ease development on the platform. It
encourages team development and rightly so because you achieve more as a team compared to
individual.
7. About DemandBlue
DemandBlue transforms customer experiences (CX) by offering Salesforce consulting through a
unique pay-as-you-use On Demand Services model
Development &
Advisory Integration
Customization
Administration &
Maintenance Lightning Migration
Support