You need to sign in to do that
Don't have an account?
doubleminus
static data cannot be found in test
I've seen some other threads around this subject, but the had a variety of issues being discussed and I'm hoping this one is more focused.
Am I missing something obvious? Here is my code:
@isTest private class TestClassForIssue { public static Account testAccount1, testAccount2; static { testAccount1 = new Account(Name='testAccount1', NumberOfEmployees=10); insert testAccount1; System.assertNotEquals(testAccount1.Id, null); } static testMethod void test1() { System.assertNotEquals(testAccount1.Id, null); }
The test1 testMethod assertion fails, saying that testAccount1.Id is null. Why is this? I'm sure I'm just missing something really obvious, but I'm not finding it...
i've not tested this in your code, but try to set SeeAllData flag to true
as per documentation
Yep that fixes it. Thanks.
I thought that had fixed it, but I ran the test again today and it's failing. Same code. This is in a sandbox fyi. cs12.