4

While deploying code in vsCode from sandbox to production I get the below error

sf:INVALID_OPERATION: INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations

As per the error, I need to change the value of testLevel but I am not able to find where and how can I change it to RunLocalTests

Could someone please help me to change the value of testLevel in vsCode

5

UPDATE 9/2019

As of Summer '19 v46.0, force:source:deploy now works when deploying to production, and you'll no longer get that testLevel error message.

You can set the test level using the -l flag and use -u to point to your connected Production org:

sfdx force:source:deploy -m ApexClass:MyClass -l RunLocalTests -u MyProductionOrg

OLD ANSWER

If you're using force:source:deploy, it doesn't work when deploying to production, which is why those testLevel errors are showing up. As of Spring 19, you can't adjust those parameters (and this is by design as far as I can tell). This limitation can be found on the force:source:deploy documentation:

The force:source:deploy, force:source:retrieve, and force:source:delete commands work on sandboxes, Developer Edition orgs, and trial orgs, but not production orgs. For production orgs, continue to use force:mdapi:deploy and force:mdapi:retrieve.

For a nice trick to deploy from Sandbox to Production, see my answer to this post - I use this on a daily basis now

  • thank you, Brian, but Instead of using the command line is there any other way to deploy code from the vs code just like we deploy code to sandBox? – gs650x May 7 '19 at 12:42
  • 1
    I don't think the Salesforce extensions for VS code are there yet - although I think on the roadmap they are proposing a UI interface to select items to deploy to Production (like you would use in MavensMate) – Brian Miller May 7 '19 at 13:47
  • Thank you for your help Brian – gs650x May 7 '19 at 13:47
  • 1
    Hi Brian, Thank you, do you think there is a way we can adjust this command per Project, so that we can do typical save and it builds/deploys automatically? – NZ Dev Nov 12 '19 at 22:15
  • It already exists for deploying to non-production orders - in VS Code, go into Settings (Cmd+,), click on the Workspace subtab, search for Salesforce, and you'll see a Push or Deploy on Save setting. Set that to true and you're set. JSON looks like: "salesforcedx-vscode-core.push-or-deploy-on-save.enabled": true. Deploying on Save to Production is a bad practice at best and don't think this setting will help you there, nor should it :-) – Brian Miller Nov 12 '19 at 22:42
1

To deploy to production using the CLI:

Deploy a Class with specific Test Class (ApexClass:MyCless = metadatatype:fileName)

sfdx force:source:deploy -m ApexClass:MyCless -l RunSpecifiedTests -r TestClass -u ConnectedOrg

Deploy Classes with specific Test Classes (comma Separated metadatatype:fileName,metadatatype:fileName)

sfdx force:source:deploy -m ApexClass:MyCless,ApexClass:TestCless,ApexClass:OtherTestClass -l RunSpecifiedTests -r TestClass,OtherTestClass -u ConnectedOrg

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.