Workflow for Data Cloud Second-Generation Managed Packages

Second-generation managed packaging (managed 2GP) for Data Cloud is a way for AppExchange partners to develop, distribute, and manage their Data Cloud apps and metadata. You can use managed 2GP packaging to organize your source data, build small modular packages, integrate with your version control system, and better utilize your custom Apex code. To learn more about when to use a 2GP packaging, see Why Switch to Second-Generation Managed Packaging?

Creating and packaging a Data Cloud app is similar to creating and packaging any app using 2GP, but there are a few key differences in the process. You still use the Salesforce CLI commands and scratch orgs, but in Data Cloud, the features that you want to include must be added to a data kit first. Then you retrieve that metadata into a Salesforce DX project and move that project to a GitHub repository. Once there, other developers can clone it, deploy the data kit metadata to their scratch org, and continue to make customizations. When development is complete, you create a version of your app, package it up, and send it out into the world.

Data Cloud 2GP packaging requires Dev Hub enabled in Developer, Enterprise, Performance, or Unlimited Editions. Scratch orgs are supported in Developer, Enterprise, Group, and Professional Editions.

The basic 2GP workflow includes these steps. See specific topics for details about each step.

Make sure to complete these prerequisites before you create and start working on a Data Cloud 2GP managed package.

To work with Data Cloud features in a scratch org, you first need to set up a scratch definition file and use the Salesforce CLI to create the scratch org.

  • To create a scratch org, from the CLI, use the command sf org create scratch -a SCRATCH_ORG_NAME -f config/project-scratch-def.json -w 10 -v DEVHUB_ALIAS. The next example shows a sample scratch definition file. See Create Scratch Orgs. This scratch org is the publisher or source org where you create the Data Cloud elements and add them to a data kit.

Sample project-scratch-def.json file with Data Cloud license.

  • Run the sf org open command to open the scratch org. Verify that Data Cloud is enabled in the scratch org by navigating to Data Cloud Setup. If you see green checkmarks, then Data Cloud is provisioned.
  • In the scratch org, create your Data Cloud elements: data streams, data mappings, calculated insights, streaming or batch data transforms, and so on. To know what Data Cloud features can be packaged, see Data Cloud Extensibility Readiness Matrix.
  • In the Data Cloud UI, create a standard data kit and add the Data Cloud features that you created to that data kit. See Create a Data Kit.
  • Review the publishing sequence for the data kit.
  • In your scratch org, from Data Cloud Setup, click Data Kits.
  • Select the data kit, and then click Download Manifest. The package.xml file that you downloaded contains all the metadata entities related to the data kit.
  • Use this package.xml file in your Salesforce DX project to retrieve the data kit metadata. From the CLI, use the command sf project retrieve start --manifest package.xml to retrieve the data kit metadata from the scratch org into the project that you created. See Retrieve Source From the Scratch Org to Your Project. After this command completes, you see new project folders that contain the data kit metadata.
  • At this point, you can upload the entire project to GitHub or any source control system. Another developer can then download that project, deploy the data kit into their scratch org, and modify it. For example, that developer can add a new data stream to the data kit. This workflow enables multiple developers to work on the same data kit.
  • From your project directory, run the sf project deploy start command to deploy the components listed in the package.xml file. See project deploy start.
  • At this point, the data kit is installed, but you still must deploy the data streams, data models, calculated insights, and all the data kit elements into the second scratch org to use them. See Deploy a Data Stream from a Data Kit.
  • After the data kit is deployed to the second scratch org, open the scratch org to see the data kit and all of its data stream bundles, data models, calculated insights, and so on.
  • The second developer can then create a data stream in their scratch org, add it to a data kit, retrieve the metadata into their project, and then upload that project to GitHub for another developer to work on.
  • From the CLI run the sf package create -n PACKAGE_NAME -t Managed -v DEVHUB_ALIAS -p PATH_TO_DATA_KIT command to create a beta Salesforce managed package that points to your data kit metadata folder. Beta packages can only be installed in scratch orgs. See package create.
  • If your Data Cloud app builds on the Data Cloud SSOT package, you must declare the SSOT package as a dependency in your sfdx-project.json file. You can find the latest SSOT package ID on the [Salesforce Partner Community] (https://partners.salesforce.com/) site. For example, if your package includes a CRM data stream that maps to a standard DMO, the SSOT package must be included as a dependency.
  • When the managed package is created, it produces a 0ho ID. Copy that ID. Next, create a managed package version using that 0ho ID.
  • Use the command sf package version create -v DEVHUB_ALIAS -k INSTALLATION_KEY -p 0ho_ID -w 45 -f config/project-scratch-def.json to create the package version. See package create.
  • When you have a package version that’s ready to distribute, promote that package to a released version. The released version can be installed in a production org. See Release a Second-Generation Managed Package.