Salesforce DX Setup – Everything You need to Know

Salesforce DX Setup

Salesforce DX Setup – Since inception, one of Salesforce’s core philosophies and the Big Idea has been to make building easy. Software should not be complex to install, set up, or customize. In fact, you shouldn’t have to even install software – it should be available to you at the click of a button – This declarative approach of Salesforce brought an end to complex and traditional methods of software development that even non-tech executives including business analysts and managers could slickly build line-of-business applications in a few clicks. However, while Salesforce was democratizing application development through clicks-not-code approach and ushering in the era of citizen programmer, there were other players who were strengthening their appeal to the traditional developer. With nuanced business requirements, modeling complex domains require more flexibility than clicks-not-code affords. Traditional methods of development weren’t dead after all.

As a result, Salesforce’s marketing and development efforts wanted to cater to the traditional developer with the introduction of Salesforce DX, a revolutionary product in the Salesforce App Cloud that allows users to develop and manage Salesforce apps throughout the entire platform in a more direct and efficient way. Used primarily by developers, Salesforce DX setup enables users to have true version control that allows them to have a better control over collaboration, auditing, disaster control and more.

Take a deeper dive into the comprehensive blog that gives you in-depth insights on how you can enable Salesforce DX environment and truly maximize its unique benefits.

Your 12 Step Salesforce DX Setup Guide

1. Set up your project

Salesforce DX introduces a new project structure for your org’s metadata (code and configuration), your org templates, your sample data, and all your team’s tests. Store these items in a version control system (VCS) to bring consistency to your team’s development processes. Retrieve the contents of your team’s repository when you’re ready to develop a new feature.

2. Salesforce DX Setup – Authorize the Developer Hub org for the project

During Salesforce DX setup, the Dev Hub org enables you to create, delete, and manage your Salesforce scratch orgs. After you set up your project on your local machine, you authorize with the Dev Hub org before you create a scratch org.

For this, you need to login to Dev/Sandbox Org from CLI
Run the force:auth:web:login CLI command on a directory where code for deploy to sfdx will be available.

sfdx force:auth:web:login –d

(or)

sfdx force:auth:web:login –setdefaultdevhubusername –setalias {ALIAS HERE}

NOTE: Login must be a valid login to your Dev/Sandbox Org and with Admin permissions.

3. Configure your local project

The project configuration file sfdx-project.json indicates that the directory is a Salesforce DX setup project. The configuration file contains project information and facilitates the authentication of scratch orgs and the creation of second-generation packages. It also tells the Salesforce CLI where to put files when syncing between the project and scratch org.

4. Salesforce DX Setup – Create a scratch org

After you create the scratch org definition file, you can easily spin up a scratch org and open it directly from the command line.

a) Create the scratch org

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.
  • Specify scratch org definition values on the command line using key=value pairs
  • Create a scratch org with an alias
  • Create a scratch org for user acceptance testing or to test installations of packages
  • Indicate that this scratch org is the default
  • Specify the scratch org’s duration, which indicates when the scratch org expires (in days)

b) Open the Org

  • To open the scratch org – sfdx force:org:open -u <username/alias>
  • To open the scratch org in Lightning Experience or open a Visualforce page, use the –path parameter – sfdx force:org:open –path lightning

c) Set default user

Copy the username and enter the following command to set the defaultusername:

sfdx force:config:set defaultusername={SET THIS TO NEW SCRATCH ORG’S USERNAME FROM THE ABOVE  COMMAND}

d) Display All Orgs

Run the following command to confirm the default Dev Hub [marked with (D)] and Active Scratch Org [marked with (U)]:

sfdx force:org:list –all

5.  Push the source from your project to the scratch org

a) To push changed source to your default scratch org:
sfdx force:source:push

b) 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 test-b4ag3oxmu@example.com

sfdx force:source:push -u test-b4ag3oxmu@example.com

sfdx force:source:push -u MyGroovyScratchOrg

c) Selecting Files to Ignore During Push

It’s likely that you have some files that you don’t want to sync between the project and scratch org. You can have the push command ignore the files you indicate in .forceignore

d) If Push Detects Warnings

If you run force:source:push, and warnings occur, the CLI doesn’t push the source. Warnings can occur, for example, if your project source is using an outdated version. If you want to ignore these warnings and push the source to the scratch org, run:

sfdx force:source:push –ignorewarnings

e) If Push Detects File Conflicts

If conflicts have been detected and you want to override them, here’s how you use the power of the force (overwrite) to push the source to a scratch org.

sfdx force:source:push –forceoverwrite

6. Salesforce DX Setup – Develop the app

a. Create Source Files from the CLI

To add source files from the Salesforce CLI, make sure that you are working in an appropriate directory.

Execute one of these commands.

  • 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

b. Edit Source Files

To edit a FlexiPage in your default browser—for example, to edit the Property_Record_Page source—execute this command.

sfdx force:source:open -f Property_Record_Page.flexipage-meta.xml

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 using 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.

To pull changed source from the scratch org to the project:

sfdx force:source:pull

To pull source to the project if a conflict has been detected:

sfdx force:source:pull –forceoverwrite

https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_pull_md_from_scratch_org.htm

8. Salesforce DX Setup – Run tests

When you’re ready to test changes to your Salesforce app source code, you can run Apex tests from the Salesforce DX CLI. Apex tests are run in your scratch org.

You can also execute the CLI command for running Apex tests (force:apex:test:run) from within third-party continuous integration tools, such as Jenkins.

9. Export The Package.xml

Export package.xml file into the temporary directory. Type the commands below in the root folder of your Salesforce DX project:

sfdx force:mdapi:retrieve -r ./temp -u {TARGETUSERNAME} -k  {SFDC PROJECT SOURCE LOCATION}\src\package.xml

10. Convert Source code to Salesforce  DX

Convert the source code to the Salesforce Developer Experience project structure by running the following command:

                sfdx force:mdapi:convert –rootdir temp –outputdir force-app

11. Track Changes Between the Project and Scratch Org

To view the status of local or remote files:

sfdx force:source:status

12. Salesforce DX Setup – 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.

Don’t want to do this Yourself?

Enter DemandBlue, a pioneer in delivering Salesforce services On Demand, a Pay-as-you-use service engagement model that delivers unique benefits when compared to other Salesforce engagement models. Our On Demand Salesforce service model is designed to deliver

  • Speed – Go live in days and weeks, not months and years
  • Value– On Demand Services for Salesforce that offers absolute flexibility and scalability – our core USP that makes us a hot favorite among our clients!
  • Success – Ranked among Top Salesforce companies – DesignRush – 70 +Happy Clients  – 3X Faster implementation – 56 / 10 Customer Satisfaction Rating on AppExchange

For a free and personalized consultation on Salesforce DX Setup, Talk to our team now!

Recent Post

Salesforce Winter '21 features for Experience Cloud

Top 10 Salesforce Winter ’21 features for reimagining your Experience Cloud Journey

As is the norm with all feature update releases, Salesforce’s Winter ’21 release is packed with features that add fluidity to workflows and help businesses achieve their goals. (more…)

Codescan

Powering up the Salesforce code structures of our customers with the CodeScan finesse

Salesforce Winter '21 CPQ

Top 6 Salesforce Winter ’21 features to enhance your Sales results for CPQ

Hello Everyone! It’s that time of the year again, when the buzz is around the Winter ‘21 feature releases for . In this blog, we are going to focus on

Top 5 Salesforce Summer '20 release features

Top 5 Salesforce Summer ‘20 release features that skyrocket productivity

Salesforce has just published its’ release notes for Summer '20! It’s packed with a plethora of enhancements and newly introduced features for Salesforce clouds and products. (more…)

Salesforce For Customer Retention

How to Use Salesforce for Customer Retention – 5 Effective Tips

Customer retention is the process of retaining customers and preventing them from switching to some other brand with a similar product or service. It plays a key role in a

Salesforce for Manufacturing

How to leverage the power of Salesforce for manufacturing?

Manufacturing industries are facing immense pressure to modernize operations and reinvent themselves.Gaining visibility into key customer metrics, streamlined collaboration between disparate departments and taking data-led decisions remain key challenges. (more…)

DemandBlue Chooses Vonage as its Preferred Contact Center Partner

DemandBlue Chooses Vonage as its Preferred Contact Center Partner

Salesforce Account-Based Marketing

Account based marketing with Salesforce – 4 proven strategies

Account-Based Marketing is ever-growing and a widely practiced B2B Sales and marketing technique that helps acquire potential companies as your clients with networking.  (more…)

DemandBlue Joins the Pledge 1% Movement, Makes Commitment to Integrated Philanthropy

Irvine, CA, September 1, 2020 - DemandBlue announced today that it has joined Pledge 1%, a corporate philanthropy movement dedicated to making the community a key stakeholder in every business.

DemandBlue announces its partnership with 123FormBuilder

DemandBlue announces its partnership with 123FormBuilder

Leave a Reply

Your email address will not be published. Required fields are marked *