11

Environment

  • sfdx-cli/7.58.2 win32-x64 node-v12.16.3
  • API 48

What's going on?

When trying to create a managed packaged version with Second Generation Packaging (2GP) -with code check- that contains this class:

global with sharing class VersionClass {
    global static void controlMethod() {
        String foo = 'someString';
    }

    global static void versionMethod() {
        Version packageVersion = System.requestVersion();
    }
}

the following error occur when calling the method containing System.requestVersion(); 1

(1) Apex Test Failure: Class.foobarbaz.VersionClass.versionMethod: line 8, column 1
  Class.foobarbaz.TestVersionClass.test_versionMethod: line 17, column 1 System.ProcedureException: Method is not supported from an unmanaged namespace

Such errors do not occur with the First Generation Packaging.

What's the expected behavior?

We expect the managed package version to be created without any errors while using 2GP.

How to reproduce?

  1. Clone the MRC Repo
  2. Ensure that you're setup for 2GP
  3. Try to create a version. You should get the aforementioned error.

Notes

1: This occurs outside of Apex test calls as well. We originally found the issue by calling a similar method through a RemoteAction in a VisualForce Page. But let's keep it simple for the example sake.

1
  • Note, the error is not reproducable without the codecheck (-c flag). Edited OP accordingly. Jun 5 '20 at 18:07
3

After contacting Salesforce, I had confirmation that Version is, to this day, not supported in 2GP, which caused the issue described here.

Update Oct.2021: still not supported.

The "least worst" workaround I found so far would be to generate an ApexClass w/ a static field or CustomMetadata that would contain the version, in a CI/CD.

2
  • What should one use instead?
    – gburnett
    Aug 2 '21 at 13:21
  • 1
    @gburnett should have put that, my bad. I edited my answer to include the least worst workaround we had. The other is of course to keep on using 1GP :/. Oct 6 '21 at 2:03

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.