6

We've recently started adopting Salesforce DX and we're trying to figure out the best way to spin up Scratch orgs.

As of now, we have multiple managed packages from the AppExchange installed in production, including Marketing Cloud Connect and Cirrus Insight and we would like to make certain scratch orgs have them.

I know there is a way to install packages with the sfdx force:package:install command, but is there any way to do it via configuration so that we don't have to execute a certain set of commands everytime we create a scratch org?

Thanks!

4

This should be possible with Second Generation Packaging. You can specify the dependencies of a package in the sfdx-project.json file.

In case you prefer to install the package in a script, you could do it like this:

#login to your DevHub
sfdx force:auth:jwt:grant --clientid [consumerKey] --username [devHubUserName] --jwtkeyfile assets/server.key --setdefaultdevhubusername

#create scratch
sfdx force:org:create -v [devHubUserName] -s -f [config/project-scratch-def.json] -a [scratchOrgName]

#push source to scratch
sfdx force:source:push -u [scratchOrgName]

#install package
sfdx force:package:install -i [packageId] -w 30 -u [scratchOrgName]
6

As example with the Salesforce CPQ 216.10.1 package, you can do the following.

  1. Create the force-app/main/default/installedPackages directory
  2. Create a file named SBQQ.installedPackage-meta.xml inside the new directory

The file you created should have the XML content below.

<?xml version="1.0" encoding="UTF-8"?>
<InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <activateRSS>false</activateRSS>
    <versionNumber>216.10.1</versionNumber>
</InstalledPackage>

You can take a look at this super simple repo as a reference.

  • I can confirm, that this also works for another tested Package: Cloud Coach Milestones. I added a CCMI.installedPackage-meta.xml. This answer is definitely underrated. – J. Lietzau Mar 11 at 9:32
  • Can you do this for an unmanaged package? eg, the packages used for some Trailhead Superbadge setups? – Thomas Taylor Mar 16 at 0:59
  • Hi @ThomasTaylor you can definitely try and let us know! My initial guess would be "no", because there's no package prefix to put into the filename, but there may be some other workaround or special notation that makes magic happen. – Marty C. Mar 21 at 16:34
  • This worked for me as well. – BrBarr Jun 11 at 17:49
3

Not at present. Scripting the installations to happen after the scratch org has been created is the most appropriate way to do what you want today.

  • 3
    Any example scripts or guidelines would improve the answer – Eric Nov 8 '17 at 7:17
1

If you add it to a git repo, CumulusCI is capable of installing dependencies (even multiple layers) based on the URL: http://cumulusci.readthedocs.io/en/latest/features.html#managing-dependencies

Additionally, the namespace and version or a zip file can be used. Examples from their documentation:

URL

project:
    dependencies:
        - github: https://github.com/SalesforceFoundation/HEDAP

ZIP

project:
    dependencies:
        - zip_url: https://github.com/SalesforceFoundation/CumulusReports/archive/master.zip
          subfolder: CumulusReports-master/src
          namespace_strip: npsp

Name & Version

project:
    dependencies:
        - namespace: npo02
          version: 3.8
          dependencies:
              - namespace: npe01
                version: 3.6
        - namespace: npe03
          version: 3.9
        - namespace: npe4
          version: 3.5
        - namespace: npe5
          version: 3.5

Note: CumulusCI is a free open source tool created by Salesforce.org. I do not work for or have any direct affiliation with this open source product besides being a user and perhaps one-day future contributor to the repo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.