In my org we have several custom profiles, including community profiles. My sfdx project is structured in a way that the profiles are included in the file repository, but are not included when the package is built. This is done because I do not want to manage my profiles from the code repository, but I need them available so that they can be pushed to my scratch orgs during development.

I have many unit tests that need to run as a user with a particular community-enabled profile. Part of the setup in these test classes is to create a Contact and an associated User using one of the community profiles in my org. When doing development I have no issues because the profiles are pushed to my scratch orgs from my codebase. When running the tests in sandboxes I have no issues because the profiles exist in Production and were copied to the sandboxes upon their creation.

The way that sfdx calculates the code coverage for a package is flawed in a way that I can no longer develop and deploy using sfdx. From what I understand, when I am creating a new package version with the --codecoverage flag, my package is built then installed onto a completely clean phantom org and the tests are run. I now have failures in my tests because the needed Profiles are not available. Adding the profiles to the package is not possible as many of them have access configured for objects that do not exist in the code repository. Additionally, the Admins needs to be able to update profile settings without requiring a package deployment.

IMO, the proper way Salesforce should have enforced this code coverage requirement would have been to have the package tests run on the target org at install time -- exactly like how change-sets work.

Any ideas?

1 Answer 1


It appears Salesforce is aware of the issue (non-packaged dependencies within unit tests). They are working on a solution and have a pilot program to address it, but as of this writing, the pilot program is not yet ready to accept users.

You must log in to answer this question.

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