An admin has added a formula field to our production org that includes a reference to a field from a 3rd party managed package.

I want to bring this field into our sfdx project codebase now, but will get an error when creating scratch orgs because our scratch orgs obviously don't have the 3rd party managed package installed.

Is there a way to get around this issue? I have tried adding the managed package to the list of dependencies in the sfdx-project.json file of our sfdx project, but it doesn't seem to get installed when a scratch org is created.

Even if that is possible, I'm still not 100% sure whether we would get charged for scratch org deployments with this package installed, as it is a paid package?

1 Answer 1


Only paid orgs pay for paid AppExchange Apps. Packages in Developer Edition, Scratch, and Sandbox Orgs are always free. You will want to create a script for setting up your Scratch Org environment that includes installing the package, something like this:

sfdx force:org:create -f config/config-file.json -s
sfdx force:package:install -p "paid-package-alias"
sfdx force:source:push
sfdx force:data:tree:import -p "data/import.plan"

Note that the setup you describe is likely correct for the situation where you want to create an Unlocked Package version. You need the dependency in the sfdx-project.json and the formula field in the source directory. The only thing you're missing is the install of the package, which must be done as a separate step after creating the Scratch Org.

Do take the time to read force:package:install for available options (e.g. if you need an installation key).

You can also use a separate folder and use force:mdapi:deploy and deploy multiple packages in a single API call, as describe in my other answer.

  • I did not get the metadata approach to work as I needed an install password (though I cannot be sure that was the issue). We added scripting using the sfdx CLI to install dependencies first. Clearly, you need cooperation from the provider of the package if they password protect it. We achieved this by having them share the password for a beta version (so not usable in a production org, but works for scratch orgs).
    – Phil W
    Sep 6, 2021 at 13:01
  • @sfdcfox thanks very much for your answer. It was v. helpful.
    – lemming
    Sep 9, 2021 at 8:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .