I'm using MetadataAPI to activate a Process Builder flow from Apex code, even I'm specifying the testLevel option, it still giving me this error:

Web service callout failed: WebService returned a SOAP Fault: INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations faultcode=sf:INVALID_OPERATION

    MetadataService.MetadataPort service        = createService();
    MetadataService.DeployOptions deployOptions = new MetadataService.DeployOptions();
    deployOptions.allowMissingFiles = false;
    deployOptions.autoUpdatePackage = false;
    deployOptions.checkOnly         = false;
    deployOptions.ignoreWarnings    = false;
    deployOptions.performRetrieve   = false;
    deployOptions.purgeOnDelete     = false;
    deployOptions.rollbackOnError   = true;
    deployOptions.testLevel         = 'RunAllTestsInOrg';
    deployOptions.singlePackage     = true; 

I would like if there something I'm not specifying or if there's a configuration I should use in order to make it work.

Note: It is working good in developer and non production environments.

  • Are you deploying any Apex components alongside? You can only choose to not run tests if your deployment is completely devoid of them. – Adrian Larson Sep 13 '16 at 12:45
  • @AdrianLarson The interesting part is the testLevel is set to 'RunAllTestsInOrg', but the deployment is receiving 'NoTestRun'. – Nick Cook Sep 13 '16 at 12:47
  • Sorry guys, looking to see if there were more instances of that class in the code, I found for some reason this same code duplicated not running any test, so I delete the code that is not used and adjusted the last version with this the same as above and it worked. – Yucel Sep 13 '16 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.