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 Sales Cloud Spring '20 Features

Reimagine your Sales with new Sales Cloud Spring ‘20 Features

Salesforce has always packed loads of pleasant surprises in their Sales Cloud Spring Releases, and as is the norm, it happened this year too. This edition is focused on delivering

Salesforce Duplicate Management

Salesforce Duplicate Management | The key to cut down the roots of duplicity

Duplicity is the bane of any database.  On average, 40- 50% of a company’s data has duplicate copies spread all across the organization. These copies on a collective scale cause

Salesforce Customer 360 Truth

Keep your employees close and customers closer with Salesforce Customer 360 Truth

Customers are an integral part of any business. Therefore, customer satisfaction is always the topmost priority for any enterprise. To ensure customer satisfaction, one must first have an understanding of

Salesforce In-App Guidance

Unboxing Salesforce Winter ’20 edition| Accelerate the adoption with Salesforce In-App guidance

Along with numerous global events taking place this winter, Salesforce has also released its much-awaited Winter '20 edition. And, as always, Salesforce has exceeded the expectations by a fair margin

Financial Services Cloud

Salesforce Financial Services Cloud | Empower your borrowers with Mortgage Innovation

Loans and Mortgages are key elements of today’s economy and there is a likelihood that every adult at some time or other has been part of this process. With time

New Salesforce Mobile App

Enhanced user experience with the New Salesforce Mobile App

We have been witnessing the tremendous improvements that salesforce solutions have brought to every industry. The New Salesforce mobile app has changed the way organizations are doing business. (more…)

Salesforce Sustainability Cloud

Salesforce Sustainability cloud | Most Eco-Friendly Tool in the Shed

With a steep rise in industrial growth all across the world, every year, the carbon emission rates significantly increase from the previous. Such a scenario has made industrialists worry about

Dreamforce Highlights

Top 10 Highlights of Dreamforce 2019

Hi, all Salesforce lovers!  I know that every one of you would have wanted to be part of the Dreamforce ’19, the event of all events.  Congratulations to the lucky

Keynote Highlights of Dreamforce 2019

It’s the Monday after the world’s largest software conference...Dreamforce! DemandBlue’s team of Customer Success Managers spent the last week seeping in Salesforce’s conference full of keynotes, sessions, and events of

Salesforce Einstein Discovery

Smarter business with the AI-powered data scientist, Einstein Discovery

In this highly competitive market, organizations are constantly trying to analyze their data and make informed decisions to outrun their competitors. That is where data analytics and data scientists play

Leave a Reply

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