Scratch To Win App
Scratch and spin win (1 Similar Apps & 1,238 Reviews) vs HBO Max: Stream and Watch TV, Movies, and More (10 Similar Apps, 13 Features, 6 Review Highlights & 55,606 Reviews). With Scratch, you can program your own interactive stories, games, and animations. Scratch helps young people learn to think creatively, reason systematically, and work collaboratively — essential skills for life in the 21st century. You can spin up a new scratch org when you want to: Start a new project. Start a new feature branch. Test a new feature. Start automated testing. Perform development tasks directly in an org. Start from “scratch” with a fresh new org. Although scratch orgs are meant to be disposable, the scratch org configuration files contain the real brawn.
Learning Objectives
After completing this unit, you’ll be able to:- Describe how the model for traditional org development differs from modular package development.
- Describe the key characteristics of a package.
Get Started with Source-Driven Development
Salesforce DX adds new tools that streamline the entire development life cycle. It improves team development and collaboration, facilitates automated testing and continuous integration, and makes the release cycle more efficient and agile.
But Salesforce DX is so 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 your version control system (VCS). It shifts your development focus from org development to package development. To learn how to migrate your existing dev processes to the package development model, head over to the Package Development Model module.
But enough with the chit-chat. Are you ready to start getting hands-on? Let’s get started setting up your environment and introducing you to some new and some familiar tools.
What’s a Scratch Org?
Many of the new tools enable you to use a new type of org called a scratch org. A scratch org is a dedicated, configurable, and short-term Salesforce environment. Scratch orgs drive developer productivity and collaboration during the development process, and facilitate automated testing and continuous integration. You can use the CLI or Salesforce Extensions for VS Code to open your scratch org in a browser without logging in. You can spin up a new scratch org when you want to:
- Start a new project.
- Start a new feature branch.
- Test a new feature.
- Start automated testing.
- Perform development tasks directly in an org.
- Start from “scratch” with a fresh new org.
Although scratch orgs are meant to be disposable, the scratch org configuration files contain the real brawn. Through the configuration file, you can configure the scratch org with different Salesforce editions and with just the features and settings you want. And you can share the scratch org configuration file with other team members. That way, you all have the same basic org in which to do your development.
Do Scratch Orgs Replace Sandboxes?
No. Scratch orgs aren’t meant to be replications of sandboxes or production orgs. Due to their ephemeral nature (and maximum 30-day lifespan), scratch orgs are perfect for developing a new feature or customization or package. And they work great for unit testing and continuous integration. Sandboxes, which contain all the metadata of your production org, are still necessary for final user-acceptance testing, continuous delivery, and staging.
Enable Dev Hub
A Dev Hub provides you and your team with the ability to create and manage scratch orgs. Scratch orgs are temporary Salesforce environments where you do the bulk of your development work in this new source-driven development paradigm.
To get started with scratch orgs, you choose an org to function as your Dev Hub. While you can enable Dev Hub in any paid org, it’s always best to practice somewhere other than production. Instead, go ahead and enable Dev Hub in a Developer Edition org or Trailhead Playground to use with this module.
You can also make any paid org your Dev Hub and grant access to developers. Get the details in the Salesforce CLI Setup Guide.
Now that you have a Dev Hub org, let’s set up the rest of your Salesforce DX tools.
Install the Command Line Interface (CLI)
Use the Salesforce CLI to control the full application life cycle of your apps. You can easily create environments for development and testing, synchronize source code between your orgs and VCS, and execute tests.Note
See the Salesforce CLI Setup Guide for complete installation instructions.
- Install the CLI.
Operating System Link to Installer macOS https://sfdc.co/sfdx_cli_osx Windows 32-bit https://sfdc.co/sfdx_cli_win Windows 64-bit https://sfdc.co/sfdx_cli_win64 Debian/Ubuntu 64 https://sfdc.co/sfdx_cli_linux
Download the archive from one of the URLs in the manifest, extract the archive, then run the ./install script.Debian/Ubuntu x86 https://sfdc.co/sfdx_cli_linux_x86
Download the archive from one of the URLs in the manifest, extract the archive, then run the ./install script.
Let’s make sure the CLI is properly installed and you know how to access online help for the commands. - In a command window, enter
sfdx
. You’ll see something like this:
Note
If you don’t see this type of response, enter sfdx update
to ensure that you have the Salesforce DX plug-in and the latest bits.
Here are some other helpful commands to get you started:
Command | What You See |
---|---|
sfdx force --help | All the available topics in the force namespace |
sfdx commands | All available commands |
OK, you’re well on your way. Now let’s continue installing the rest of the Salesforce DX tooling.
Log In to the Dev Hub
To get started, log in to the Dev Hub using the CLI, so you’re authorized to create scratch orgs. You can use sfdx auth:web:login
to log in to various orgs, and we’ve provided some options to help you manage those orgs.
- To authorize the Dev Hub, use the web login flow:Adding the
-d
flag sets this org as the default Dev Hub. Use the-a
flag to set an alias for the org (something catchy like DevHub). An alias is much easier to remember than the unique Dev Hub username. Important: Only indicate the-d
flag for your Dev Hub. If you use it with a different org, you can’t create scratch orgs until you correctly identify the Dev Hub using theconfig:set
command. - Log in with your credentials.
Once successful, the CLI securely stores the token along with the alias for the org, in this example, DevHub. You can close the Dev Hub org at any time.
You can close the Dev Hub and still create scratch orgs. However, if you want to open the Dev Hub org to look at active scratch orgs or your namespace registry, the alias comes in quite handy:
A Bit More on Org Management
It’s likely you have many orgs, including sandboxes and your production org. With the CLI, you can also log in to them using these commands. When you log in to an org using the CLI, you add that org to the list of orgs that the CLI can work with in the future.
Log In to Sandboxes
If you create an alias for the sandbox ( -a
flag), you can reference it by this alias instead of its long and often unintuitive username.
For example:
Important
Remember, don’t use the -d
flag. If you do, the CLI thinks the org is your Dev Hub, and then you’ll see an error when you try to create a scratch org.
The Power of Aliasing
As you might imagine, aliasing is a powerful way to manage and track your orgs, and we consider it a best practice. Why? Let’s look at scratch org usernames as an example. A scratch org username looks something like test-7emx29rtpx0y@example.com
. Not easy to remember. So when you issue a command that requires the org username, using an alias for the org that you can remember can speed things up.
Scratch And Win Money
View All Orgs
At any point, you can run the command sfdx force:org:list
to see all the orgs you’ve logged in to. Adding the --verbose
option provides you even more info.
Now you’re really ready to get going—let’s go build a new app with the Salesforce CLI and scratch orgs.