7

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!

5

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]
| improve this answer | |
  • 1
    Just because you can specify the dependencies in the sfdx-project.json doesn't mean that the SFDX CLI automatically installs those packages in your scratch org when you create it - I've tried this out. – Phil W Apr 30 at 7:10
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.

| improve this answer | |
  • 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 '19 at 9:32
  • Can you do this for an unmanaged package? eg, the packages used for some Trailhead Superbadge setups? – Thomas Taylor Mar 16 '19 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 '19 at 16:34
  • This worked for me as well. – BrBarr Jun 11 '19 at 17:49
  • 1
    @PhilW you can install multiple packages in the same push or deployment with sfdx, and with the Metadata API as well. However, if there are dependencies, in my experience Salesforce won't know which package to install first. In those situations you'll have to manually script the correct order of deployments. – Marty C. Apr 29 at 19:58
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.

| improve this answer | |
  • 5
    Any example scripts or guidelines would improve the answer – Eric Nov 8 '17 at 7:17
2

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.

| improve this answer | |
0

Go to AppExchange listing and click 'GetItNow' and log in with the DevHub credentials used to create the Scratch org. When prompted if to install in a Production or Sandbox, click Sandbox and login with your Scratch org credentials. You could generate a password for your Scratch org admin user with force:user:password:generate sfdx CLI command

| improve this answer | |
  • This really doesn't answer the question. The poster is looking for ways to automate package installation. – David Reed Aug 13 at 23:17
  • My bad. I mistook configuration for admin configuration. Apologies. – Naga Aug 13 at 23:25

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.