Skip to main content

Get Ready to Create Your First Unlocked Package

Salesforce Developer Experience (DX) provides a new set of tools and processes to streamline the development lifecycle for Salesforce developers. These new tools focus on team development and automation, and the notion of modular, package-based development. Modular development is a game changer for both customers and ISVs.

In this quick start, we introduce you to Unlocked Packages as a mechanism for managing change to the internal business apps you build. If you’re looking for a deep dive into unlocked packages, look at the Unlocked Packages for Customers module.

What Is an Unlocked Package?

If you’re new to packaging, you can think about a package as a container that you fill with metadata. It contains a set of related features, customizations, and schema. Salesforce offers several types of packages, each with unique characteristics. For now, you’re going to work with a special package type, an Unlocked Package, which is especially suited for internal business apps.

Unlocked packages help you add, edit, and remove metadata in your org in a trackable way. You can apply your source and metadata to multiple orgs, and upgrade your Salesforce apps easier and faster. Packages encapsulate all the metadata changes and updates you plan to make.

With an unlocked package, you have a lot of flexibility. Your admins can make changes directly in production in response to emergency change requests because metadata in unlocked packages can be modified in a production org. At the same time, this flexibility comes with responsibility. Ensure that you have the proper governance in place to prevent cases where package updates overwrite changes that admins make directly in production. This use case is covered in more depth in the Unlocked Packages for Customers module.

Configure Your Environment

Before you can get to the good stuff, let’s set up a new Trailhead Playground and enable the Dev Hub and packaging settings in it.

  1. To create a new Trailhead Playground, locate the hands-on challenge at the end of this unit. Click the playground information to the left of the Launch button.
    Then select, Create Playground.

    Note: While it's possible to reuse an existing Trailhead Playground, starting with a fresh playground ensures you are working with a clean environment.
  2. After creating a new Trailhead Playground, click Launch to open the playground. Then ensure you know both the username and password for the playground. You’ll need this information in an upcoming step.
    See Getting Your Username and Resetting Your Password.
  3. From Setup in your Trailhead Playground, enter Dev Hub in the Quick Find box and select Dev Hub. Click Enable Dev Hub and then click Enable Unlocked Packages and Second-Generation Managed Packages.
  4. Create a GitHub account, if you don't already have one.
  5. Install Salesforce CLI on your computer.

After you build your unlocked package, you test it in a scratch org. Eventually, you install it in one of your more permanent orgs, like a sandbox. During this quick start, we'll install your unlocked package in to your Trailhead Playground (TP).

Once you have your credentials, log in to your TP using Salesforce CLI. Be sure to give the TP an alias to make your life easier later in the quick start.

sf org login web --alias MyTP

Run sf org list to confirm that your TP credentials are stored locally.

=== Orgs
     ALIAS       USERNAME                         ORG ID              CONNECTED STATUS
───  ──────────  ───────────────────────────────  ──────────────────  ────────────────
(D)  DevHub      myDevHub@example.com             00DB0000000Ige5MAC  Connected
     MyTP        myName@cunning-bear-311000.com   00D6A000000fH8CUAU  Connected
     TestingOrg  name@example.com                 00DB0000000Im58MAC  Connected
ALIAS     SCRATCH ORG NAME  USERNAME             ORG ID              EXPIRATION  DATE
────────  ────────────────  ───────────────────  ──────────────────  ────────────────
Scratch1  myAcme            test@example.com     00DZ000000N8ItoMAF  2020-03-01

Now, whenever you run a command from the Salesforce CLI and use --aliasMyTP, it performs the operation against your TP.

Download the Sample App from GitHub

To demonstrate the power of unlocked packages, we’re going to use a sample app that intrinsically highlights the value of the Lightning Platform. It’s fast, it’s fun, and it empowers you to search for and post your favorite animated GIFs to Chatter. That’s right, meet GIFter, the GIF-to-Chatter app that you didn’t know that you needed.

The app is available for you to use in GitHub: https://github.com/developerforce/GIFter

To get started, clone the repository to create your own version of the app to use and modify independent of the sample.

  1. Open a new Terminal (Mac) or Command Prompt (Windows) window, then clone the app repository.
    git clone https://github.com/developerforce/GIFter.git
  2. Change to the directory.
    cd GIFter
  3. Open your scratch org definition file (config/project-scratch-def.json ) in your favorite text editor.

    GIFter is an open-source project that can change at any time. To ensure that you can successfully complete the steps, let’s make sure your scratch org definition file looks like this one to start out.
    {
      "orgName": "GIFter",
      "edition": "Developer",
      "features": [],
      "settings": {
        "lightningExperienceSettings": {
          "enableS1DesktopEnabled": true
        },
        "mobileSettings": {
          "enableS1EncryptedStoragePref2": false
        }
      }
    }
Note

If this time is your first using a GitHub repository or you need a refresh on these concepts, look at the Git and GitHub Basics Trailhead Module or review the GitHub Help articles.

You now have the app. Let’s unlock an infinite selection of animated GIFs!

Create a GIPHY App

I know you’re excited to start searching for animated GIFs and post them to Slack. Who isn’t? But, for this project to work, you first create a GIPHY app and get yourself an API Key.

  1. Head over to https://developers.giphy.com/. After you create and log in to your account, select Dashboard. This app acts as the liaison between our app and the GIPHY API.

  2. Select Create an App.

  3. Select API Selected, and Next Step.

  4. Give the new app an App Name and App Description, then click Create New App.

    You can choose whatever you want, but we recommend “GIFter” as it’s always good to keep it related to the intended function. 
  5. Copy the displayed API Key, so you can use it in the next step.

  6. In the GIFter app you cloned earlier, let’s update the code to use your GIPHY API key.

    Open the file force-app/main/default/staticresources/GIPHY.resourceusing your favorite IDE or text editor. Did you know that we have amazing extensions for Visual Studio Code? Grab the Salesforce Extensions for VS Code from the Visual Studio Marketplace.

    In the file GIPHY.resource (which is a JavaScript file shared by the Lightning components in the app) see the following line of code.
    var apiKey = "YOUR_GIPHY_API_KEY";
    Replace YOUR_GIPHY_API_KEY with your Api Key.

  7. Save the GIPHY.resource file.
Note
Your API key is a secret! Do not commit your API key to a public GitHub repository. While it’s beyond the scope of this quick start, there are many ways for you to securely keep track of secrets. For now, don’t check it in!
All the prework is done. Great job! Now let’s go post some animated GIFs to Chatter.

We won't check any of your setup. Click Verify Step to go to the next step in the project.

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities