Timeline for Unit testing a callout on batch class, I got some differences when using different standard objects
Current License: CC BY-SA 3.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 18, 2018 at 18:57 | vote | accept | Renato Oliveira | ||
Sep 24, 2018 at 10:12 | |||||
Apr 18, 2018 at 18:55 | history | edited | battery.cord | CC BY-SA 3.0 |
added 131 characters in body
|
Apr 18, 2018 at 18:44 | history | edited | battery.cord | CC BY-SA 3.0 |
added 978 characters in body
|
Apr 18, 2018 at 18:35 | comment | added | battery.cord | If you have any other questions or implementation problems, ping me. This convo can also probably be moved to chat, ill be putting the details of these comments into the question. | |
Apr 18, 2018 at 18:33 | comment | added | battery.cord |
Looking at the log I think it was failing after trying to execute the second batch job, I think that has something to do with it - removing (or moving them out of the Test.Start/Stop) the extra execute/start/finish methods I was using for testing makes the error go away. Seems like trying to execute the batch more than once in a single context will also cause this error. If you insert a ContentDocument in the @testSetup method, it'll still cause the same failure - even if the job is trying to work off attachments ! I'll make one last edit, but we should probably wrap this up..
|
|
Apr 18, 2018 at 18:16 | comment | added | Renato Oliveira | Interesting, the test method works just fine with the Attachment object. The method that is failing is the one with the Content Document. It is the same logic for both objects, but I separate the test on two distinct methods. | |
Apr 18, 2018 at 18:14 | comment | added | battery.cord |
.. This actually fails when working with Attachments as well, if you replace all the references in the job & test with Attachments, you get the same error pattern, which doesn't line up with your original post.. Honestly I have no idea what the root of this error is, but I think the solution on how to cover your test is clear from my answer.
|
|
Apr 18, 2018 at 17:57 | comment | added | battery.cord |
Definitely seems like it, something isn't working right behind the scenes. Both Database.ExecuteBatch and System.ScheduleBatch return a valid job id (meaning the job queue can fit them), but then any callouts executed in this context fail. Even returning values directly from the start method, without any queries in the test or the batch class will cause this error if run with either of those methods. Run the same methods yourself, in the same context, and it works without issue.
|
|
Apr 18, 2018 at 17:52 | comment | added | Renato Oliveira | This does seems like a bug though, correct? It makes little sense to me that an attachment can be created, but a content document can not. I wonder if it is worth it to reach someone on Twitter about this or log a case... | |
Apr 18, 2018 at 17:47 | history | edited | battery.cord | CC BY-SA 3.0 |
added 1579 characters in body
|
Apr 18, 2018 at 17:33 | history | answered | battery.cord | CC BY-SA 3.0 |