I've recently added some
Field Level Security checks into the
Apex code of a
2GP managed package.
But when I run:
sfdx force:package:version:create ...
A lot of the tests fail, saying the fields are not createable.
I found this question:
this command takes what you have in your local source folder and then uses via the DevHub org spins up a transient scratch org and checks the metadata deploys there.
Therefore, I assume the user running the tests does not have access to the fields via the
Permission Set which is included in the package.
I tried adding a
InstallHandler but it doesn't get run, because it is not a package yet.
I cannot include a modified
System Administrator profile in a
Managed Package ref this question
I am about the update all the tests to use
System.RunAs with a user which has the
Permission Set applied, but it doesn't feel right...
I am not sure what the best practice is here?