I'm trying to create a version of an unlocked package using the codecoverage parameter, but it's failing at the first line of the first method in the test class.

    static void makeData(){
        Id acctLender = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosByName().get('Lender').getRecordTypeId();

The error I'm getting is: System.NullPointerException: Attempt to de-reference a null object

I replaced the above code with a SOQL search for the RecordType Id, and got a different error message with the same theme: List has no rows for assignment to SObject

I've tried explicitly pointing it to the dev hub with the -targetdevhubusername parameter, but that makes no difference.

The command entered was: sfdx force:package:version:create -p LenderBatch --codecoverage -targetdevhubusername username -x -w 10

Is there a parameter I'm missing here? Many thanks for any help.

*** Update

Another option apart from the pilot mentioned by sfdxfox, is the orgdependent parameter currently in beta.

  • Does your package succeed without the code coverage option? Are you packaging a record type with the label (not developer name) Lender?
    – David Reed
    Oct 20, 2020 at 4:28

2 Answers 2


Unlocked Packages run their tests in a completely blank org, similar to creating a brand new Scratch Org, deploying your tests there, and then running them. As such, if the metadata is not in your package, it doesn't exist for the purposes of your test. There is a pilot to work around this limitation, but for now, you'll need to include the record type in your metadata in order for it to be available for the test. Consequently, if you install the package in an org, it will create or update the record type in that org that matches the Developer Name for the record type.

  • As I feared. Does including the record type mean that the package can't be uninstalled?
    – resedasue
    Oct 20, 2020 at 5:17
  • @resedasue Generically speaking, you can uninstall the package regardless of its contents. What concerns did you have around this?
    – sfdcfox
    Oct 20, 2020 at 5:47
  • That I'll need to include customizations (e.g. fields,record types) that will cause an issue when uninstalling, if referenced by code, validation, layout, etc.
    – resedasue
    Oct 20, 2020 at 15:41

For anyone arriving here facing the same quandary:

If you are not an ISV, the "Specify Unpackaged Metadata for Package Version Creation Tests (Pilot)" will not be available to you.

In my case, I needed to uninstall the packages and create new ones using the orgdependent parameter.

Uninstalling proved tricky, custom objects and fields had made their way into flows and reports outside the package. Also, uninstalling would mean deleting objects and their data.

In speaking with Salesforce Support, they advised releasing a new version of the package without these objects and fields. By not including them in the package, when the new version is deployed to the org, the metadata is no longer bound to it and released to become one with the "happy soup".

But that brought me back to original problem - unable to deploy due to the Winter '21 code coverage requirement.

Fortunately, the answer came from this link here - components can be removed via the UI (Setup/Installed Packages). After doing that I was able to successfully uninstall.

When a new package is created with the orgdependent parameter, the components that were removed via the UI can be included. This will “recapture” them into the package on deployment.

You must log in to answer this question.

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