We're an ISV transitioning from a classic single org dev setup to DX. We're developing a first generation managed package. One of the problems we're running into is the use of System.requestVersion in our code base.

The documentation of System.requestVersion states:

The requestVersion method isn’t supported for unmanaged packages. If you call it from an unmanaged package, an exception will be thrown.

The code calling that method is running fine in our classic dev org, but when it is running in a scratch org, System.requestVersion throws an exception that it cannot be called from unmanaged code.

Is there a way that you can set up your scratch org such that the code is running in a managed package?

My sfdx-project.json:

  "packageDirectories": [
      "path": "app",
      "default": true,
      "package": "p",
      "versionNumber": "42.0.0"
  "namespace": "n",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "44.0"

The values for "package" and "namespace" match with those in our dev org.

My project-scratch-def.json:

    "orgName": "Company",
    "edition": "Partner Developer",
    "country": "NL",
    "language": "NL",
    "features": ["AuthorApex", "Communities", "MaxApexCodeSize:15"],
    "orgPreferences" : {
        "enabled": ["ChatterEnabled", "NetworksEnabled", "S1DesktopEnabled"]
  • Sounds like you need something as mentioned in this answer
    – Raul
    Jan 18, 2019 at 19:08
  • Thanks for the suggestion, I read that thread and it might be a workaround. However, it is a workaround. I'd be interested to hear whether it is possible to set up a scratch org in such a way that the code behaves similar to in our current dev org. Jan 18, 2019 at 22:35

1 Answer 1


tl;dr you cannot

While researching another issue I found this thread on the SF Trailblazer Community (requires login). In this thread Chris Peterson (who works as PM at Salesforce) states that this is a problem that they have recognized but that is not on the immediate roadmap. Chris also posted the workaround that Raul suggested; I've adopted the workaround as well.

You must log in to answer this question.

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