I am trying to deploy config only changes (only a permission set change) and while running:

sfdx force:source:deploy -x manifest/package.xml -u Prod

I get the error:

INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations

Whereas when I convert the metadata from the Source format to Mdapi format and then try to run:

sfdx force:mdapi:deploy --deploydir mdapi --targetusername Prod

It runs successfully without asking me to run tests.

Why this difference in the behavior between source:deploy and mdapi:deploy? Is there something I am missing?

1 Answer 1


With both force:mdapi:deploy and force:source:deploy, there is a parameter to specify the test level (-l or --testlevel).

Looking through the documentation, it seems like both should be using the "NoTestRun" level (since you're not including apex or triggers) though it is possible that there is a discrepancy between how the mdapi command is run and how the source command is run. This behavior suggests that either:

  • The force:mdapi:deploy command is actually running with the "RunLocalTests" test level
  • The force:source:deploy command is incorrectly applying a check for the test level when no apex/triggers are being deployed

The metadata api also changed for api >= v34.0. Prior to v34.0, local tests were run when deploying a permissionSet (same with a handful of other metadata types).

There is also a github issue on the sfdc cli project that seems to be almost word for word a match for your issue, which contains a nifty workaround. Simply use the "RunSpecificTests" test level, and provide a test name that does not exist as a test class (it seems like using an Apex class name works, but that's not something I'd suggest doing) in your target org.

Something like sfdx force:source:deploy -m PermissionSet:myPermSetName -u Production -l RunSpecifiedTests -r notATest

  • 1
    The mdapi actually is kind of buggy, if I recall correctly; it often requires more than NoTestRun even when you're not deploying actual code. I don't think this is a CLI problem, but an API problem. It'd be interesting to see what the Deploy Status screen reads when running force:source:deploy.
    – sfdcfox
    Nov 11, 2021 at 16:11

You must log in to answer this question.

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