9

I have noticed very strange behavior while executing test.

In one method on the class i test Savepoint is created. This method is used also in test for creation of records. After that there is a startTest statement so it should run ok.

But for some reason i get:You cannot make callout after creating a Savepoint exception thrown. I tried googling but there is not a single result that would even appear.

What makes it even weirder is that the the similar setup works in another test case.

Has anyone ecountered this?

7
  • Hello, zokito, have you checked the test execution log to confirm whether the test method is or isn't attempting to make a callout, after creating a Savepoint?
    – Marty C.
    Commented Feb 16, 2014 at 5:20
  • hi Marty, the issue lies in the following (i think) i have the following setup - static manager class that does all the operations on records of certain type in one create operation, since there are a lot of consecutive dml calls i have Savepoint set (savepoint is method scoped). This part is all done before start test is called (i think this should do all the commits etc so the context should be clear). I then do the callout on the same static class and i get this exception. The weird thing is if i do a callout directly from test not from the manager class (all is static) it goes well.
    – zokito
    Commented Feb 17, 2014 at 22:49
  • And answer to your question is it does but after test.StartTest
    – zokito
    Commented Feb 17, 2014 at 22:56
  • Hello, zokito, is there any way you can post some of your code? I tried to reproduce the error you got, but I got a very different error message: Methods defined as TestMethod do not support Web service callouts, test skipped
    – Marty C.
    Commented Feb 18, 2014 at 18:20
  • Hi Marty i can't really post the code since i have an nda but i can make a stripped down version of the setup but i currently don't have proper time to do it. And for your situation you should use the HttpCalloutMock interface as described here salesforce.com/us/developer/docs/apexcode/Content/…
    – zokito
    Commented Feb 19, 2014 at 21:49

1 Answer 1

8

If anyone ends up in the same situation the way to solve this is:
if(!Test.isRunningTest()) { create savepoint }

be careful not to forget to use the same
if(!Test.isRunningTest()) { restore savepoint }

if you're restoring.

1
  • one s to many in Test
    – zokito
    Commented Mar 3, 2014 at 20:48

You must log in to answer this question.

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