So I have this test Class, when I run the test from inside Salesforce it fails. When I run the test from the Dev Console it passes. Why are the results different when I invoke the test from a different interface?

Just to be completely clear, when I describe running the test from inside Salesforce, I mean Setup -> Develop -> Apex Test Execution (select the test and run it).

When I describe running it from the Dev Console it's Test -> New Run -> (Select the test Class and run it).

The test also fails when validating a change set, however, change set deployments don't seem to be reporting the failure.

The nature of the failure is due to a DML exception that appears to be related to something build in Process Builder.

Are Apex tests run differently depending on how they are invoked?


Yes, there's runTests() and compileAndTest(), and they do run differently. In theory, they should run identically, but typically because of platform bugs, they do not. In those situations, you should try to get a bug opened with R&D. There's usually a workaround, but without support's help, it may be hard to pinpoint what needs to be done. Usually, compileAndTest will allow deployments that runTests reports as failures.

  • Also, long-running test or CPU timeout is quite frequent on sandbox, in prod it just runs fine – Pranay Jaiswal Feb 7 at 19:56
  • 1
    @PranayJaiswal that might simply be different TraceFlag settings, too. Setting debug levels too high (e.g. everything set to maximum trace levels) can cause CPU timeouts. Unless you're actually debugging, it's usually worthwhile to disable logging. – sfdcfox Feb 7 at 20:05

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.