Breaking 5 Myths – Scratch Orgs & Salesforce DX

Its been around 3 years that Salesforce has released new tooling set for developers – Salesforce DX. I’ve been working on Salesforce since days of S-Control around 2008 and have seen extreme changes on platform for better.

To be honest, it’s tough to keep yourself up to date on latest changes that Salesforce has been doing , however there are resources like Medium, Trailhead and many other blogs to help you get up to speed.

I’ve seen days and written code on Force.com IDE, Developer Console, many web based IDE and definitely my heart and love at the moment is with VSCode more importantly Scratch Org & unlocked packages.

Purpose of this blog post is to bust some of myths around using Scratch Org in Salesforce DX however before I start, lets agree on below aspects of project development & management

  1. Most of projects in Salesforce follows Agile and one of most important aspect of Agile is Devops. Your team should spend enough time & energy in planning Devops strategy like branch structure, tools, processes etc. In my experience , Devops is more about process rather than tool.
  2. On basis of above point, Source of truth for code & configuration should be your Source Code Management , which in most of cases is Git.

What if your project is not following above 2 principles ? Well, you might already able to relate some of problems like why code is overwritten , no track of which class or fields created by who and why ? Your team spending most of time fixing deployment issue instead of working on actual implementation.

Lets not spend more time and directly jump on some of myths about using scratch org

Myth 1 – Scratch Org is only for packaging & ISV partners

Scratch Org can be used for quick POC or actual implementations. I’ve been using scratch org for each user story which normally takes 1-3 weeks of implementation. Every time, scratch org created, I get liberty to choose which Git branch would be source of truth. Can you refresh dev pro sandbox from Full copy or use 10 days old code that was in production ? There are many other considerations while creating sandbox, you don’t have much control on which metadata would be carried over as starting point.

Continue reading “Breaking 5 Myths – Scratch Orgs & Salesforce DX”

Solve for Common Errors in Unlocked Packages

How to solve most frequent and common errors in unlocked packages

Error 1 : Language not supported in translation workbench. fr_CA Not available for deploy for this organization.

Solution : This error could be thrown from Salesforce DX while create unlocked package version. To solve this, we need to provide of scratch org configuration file informing that package needs translation. It seems little off that why would unlocked package need path to scratch org , however this is how it is. Example file project-scratch-def.json

{
    "orgName": "DemoScratch",
    "edition": "Developer",
    "features": [],
    "settings": { 
        "chatterSettings": {
            "enableChatter": true
        },
        "lightningExperienceSettings": {
            "enableS1DesktopEnabled": true
        },
        "languageSettings": {
            "enableTranslationWorkbench": true,
            "enableEndUserLanguages": true,
            "enablePlatformLanguages" : true
          }
    }
}

Also, note that edition is developer.

If you use edition enterprise and your unlocked package using some manage package component, it will start throwing various errors.

chances of getting error in enterprise edition lot higher compared to developer edition

Now, Sample command to create unlocked package version

sfdx force:package:version:create -p <package name> -d force-app -k <password> -w 10 -v <dev_hub_user_alias> -f config/project-scratch-def.json

You can refer this blog post for list of all frequently used SFDX commands.

Install Manage Package in Scratch Org using Salesforce DX

Install CPQ, Field Service Lightning, B2B Commerce cloud in Scratch Org using SFDX Command

There are tons of useful SFDX commands available to help automate Salesforce deployment. However one of most important aspect of Salesforce DX is capability of spinning org within few minutes with features enabled like Person Account, Communities etc.

There could be times, where these commands might not be sufficient. I recently cam across such scenario where I wanted to install manage package for quick capability check.

Scanned through documentation, Stack Exchange and spent lots of time figuring out on how to automate package installation. There are many commands available to install second generation package but not manage package itself. Then I came across marty chang’s github repository with instruction.

Continue reading “Install Manage Package in Scratch Org using Salesforce DX”

Build a Salesforce DX Plugin in 15 Min

My Dreamforce Session to create a Salesforce DX plugin in 15 minutes

Before deploying metadata in Sandbox of production, have you felt that how great it would be to generate configuration workbook ? Or compare sandboxes for difference ? Or check if fields are used on any page layouts or not ? Dear reader, you are in need of custom Salesforce DX plugin.

You heard it right, Salesforce DX allows custom plugin development. So now question is, how do you connect to Salesforce Org ? Do you need to know about OAuth or Single Sign On (SSO) ?

Complete source code is available on my Github repository here. Continue reading “Build a Salesforce DX Plugin in 15 Min”

Using SalesforceDX (SFDX) with non Scratch Orgs

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags , with 15 Comments on Using SalesforceDX (SFDX) with non Scratch Orgs

How to use SalesforceDX (SFDX) with Sandbox, Developer and Production Orgs

We have gone through few blog posts about SFDX and its capabilities in past. In this post, I will explain steps on how to use SFDX with developer, Sandbox or Production Org. In short we will discuss how to use SFDX with non Scratch Orgs. We would be using official Salesforce IDE for SFDX, which is VSCode.

Assumption – VSCode extension is already installed in your VSCode.

  1. Create SFDX project in VSCode

Open VScode and press cmd+Shift+p, It will give some option. Select SFDX: Create Project.

SFDX : Create Project
SFDX : Create Project

Continue reading “Using SalesforceDX (SFDX) with non Scratch Orgs”

Import and Export Records using Salesforce DX

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags , , with 7 Comments on Import and Export Records using Salesforce DX

Using Salesforce DX to Export and Import records into regular Salesforce Instances without dependency on developer hub org

In today’s continuous integration solution built for Salesforce, if you need to load sample data into Salesforce then either we use command line dataloader or custom tool built to import export records.

With Salesforce DX, we can import and export records right from Salesforce DX. Again, if you are new to Salesforce DX, then first read this blog post to quickly understand what is Salesforce DX. 

We don’t need Developer Hub or Scratch Orgs to use Salesforce DX for import and export. In this blog post, I have used my regular developer org for demo.

First step as always, to make sure if Salesforce DX CLI is connected to your Org or not ? If its not connected then use below command to connect and give alias which is easy to remember. Continue reading “Import and Export Records using Salesforce DX”

Use Metadata API with Salesforce DX

How to use SalesforceDX to deploy metadata in Sandboxes or Non-Scratch Salesforce instances

If you have existing VCS which stores metadata information about your Salesforce instance in old format, dependent on package.xml and you want to use Salesforce DX then this blog post is for you. As you might already know, Salesforce DX does not need package.xml and can automatically detect changes in your Salesforce instance, therefore new Salesforce DX project format is different. In this blog post we will see, how Salesforce DX can be used without enabling Developer Hub and using Salesforce DX with normal Salesforce instances.

There are two solution to this problem

  1. Keep using old Project format and use Metadata API to retrieve and deploy
  2. Convert old project format to Salesforce DX project Format

Continue reading “Use Metadata API with Salesforce DX”

Most Frequently used SFDX Commands

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags , , , with 28 Comments on Most Frequently used SFDX Commands

Introduction and basics of Salesforce Developer Experience (Salesforce DX) with source code and Video tutorials

Table of Content

If we already have Salesforce Metadata API, Force.com IDE and other tools then why do we need one more tool like Salesforce DX ?

In tools like Changeset, Metadata API or Force.com IDE, source of truth is Sandbox. Although we can setup process and continuous integration (CI) to use some source code management (SCM) like Git or SVN. However these kind of setup takes time, expertise and lot of effort.

Salesforce DX not only solves above problem but

  • Ability to consider SCM as source of truth
  • Use any favorite IDE or any SCM
  • Powerful CLI to help minimizing complexity of setting up CI
  • Updated Force.com IDE to support Salesforce DX if you are not comfortable with CLI
  • and most important, spin off Scratch Orgs within minutes through script to quickly work on POC or package based development

What are scratch Orgs ?

Salesforce DX can be enabled for any Salesforce instance and they are known as Developer Hub. One Developer Hub can have multiple Scratch Orgs. Scratch Orgs are temporary Salesforce org which can be created quickly and metadata can be deployed from SCM. These kind of Orgs can be used by developers to perform quick proof of concept or build and test packages. Once package is build and saved back on SCM, scratch org can be destroyed easily.

Continue reading “Most Frequently used SFDX Commands”