• Sean Healy 33
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Was trying to file a case for support to make sure this is a bug, but was pushed here instead. 

Below is a simple snippet, that can be run in a spring'16 developer org, which reproduces a System.NoDataFoundException. The test class was designed to create a number of notes, set the created date in the past, and then run a batch apex to remove notes created past a certain date. When trying to run the class, the exception is generated. The account created in the snippet does not generate the same exception. 
@isTest
public class NoteCleanUp_Test {
    
    @isTest
    public static void CleanUp_Test() {
        Account testAccount = new Account();
        
        testAccount.Name = 'Test Account';
        
        insert testAccount;
        
        System.assertNotEquals(null, testAccount.Id);
        
        Note testNote = new Note();
        
        testNote.Title = 'Test Account Note';
        testNote.Body = 'Test Account Note Body.';
        testNote.ParentId = testAccount.Id;
        
        insert testNote;
        
        System.assertNotEquals(null, testNote.Id);
        
        Test.setCreatedDate(testAccount.Id, DateTime.now().addMonths(-6));
        Test.setCreatedDate(testNote.Id, DateTime.now().addMonths(-6));
        
        Test.startTest();
        
        System.assert([SELECT COUNT() FROM Note] > 0);
        
        Test.stopTest();
	}
}

The above code will generate the exception:
System.NoDataFoundException: The sObject with the ID 00261000003I5rmAAC isn’t part of this transaction. Provide the ID of an sObject that this test method created.

With a stack trace of:
Class.System.Test.setCreatedDate: line 81, column 1
Class.NoteCleanUp_Test.CleanUp_Test: line 25, column 1

I've also posted this on the salesforce stackexchange network, which you can view here: http://salesforce.stackexchange.com/questions/117473

I'd really like either someone to confirm that yes, this is in fact a bug, or for someone to point out a error in the above code to allow me to write a test class without using a workaround (such as those specified on the linked stackexchange question).
Was trying to file a case for support to make sure this is a bug, but was pushed here instead. 

Below is a simple snippet, that can be run in a spring'16 developer org, which reproduces a System.NoDataFoundException. The test class was designed to create a number of notes, set the created date in the past, and then run a batch apex to remove notes created past a certain date. When trying to run the class, the exception is generated. The account created in the snippet does not generate the same exception. 
@isTest
public class NoteCleanUp_Test {
    
    @isTest
    public static void CleanUp_Test() {
        Account testAccount = new Account();
        
        testAccount.Name = 'Test Account';
        
        insert testAccount;
        
        System.assertNotEquals(null, testAccount.Id);
        
        Note testNote = new Note();
        
        testNote.Title = 'Test Account Note';
        testNote.Body = 'Test Account Note Body.';
        testNote.ParentId = testAccount.Id;
        
        insert testNote;
        
        System.assertNotEquals(null, testNote.Id);
        
        Test.setCreatedDate(testAccount.Id, DateTime.now().addMonths(-6));
        Test.setCreatedDate(testNote.Id, DateTime.now().addMonths(-6));
        
        Test.startTest();
        
        System.assert([SELECT COUNT() FROM Note] > 0);
        
        Test.stopTest();
	}
}

The above code will generate the exception:
System.NoDataFoundException: The sObject with the ID 00261000003I5rmAAC isn’t part of this transaction. Provide the ID of an sObject that this test method created.

With a stack trace of:
Class.System.Test.setCreatedDate: line 81, column 1
Class.NoteCleanUp_Test.CleanUp_Test: line 25, column 1

I've also posted this on the salesforce stackexchange network, which you can view here: http://salesforce.stackexchange.com/questions/117473

I'd really like either someone to confirm that yes, this is in fact a bug, or for someone to point out a error in the above code to allow me to write a test class without using a workaround (such as those specified on the linked stackexchange question).
Was trying to file a case for support to make sure this is a bug, but was pushed here instead. 

Below is a simple snippet, that can be run in a spring'16 developer org, which reproduces a System.NoDataFoundException. The test class was designed to create a number of notes, set the created date in the past, and then run a batch apex to remove notes created past a certain date. When trying to run the class, the exception is generated. The account created in the snippet does not generate the same exception. 
@isTest
public class NoteCleanUp_Test {
    
    @isTest
    public static void CleanUp_Test() {
        Account testAccount = new Account();
        
        testAccount.Name = 'Test Account';
        
        insert testAccount;
        
        System.assertNotEquals(null, testAccount.Id);
        
        Note testNote = new Note();
        
        testNote.Title = 'Test Account Note';
        testNote.Body = 'Test Account Note Body.';
        testNote.ParentId = testAccount.Id;
        
        insert testNote;
        
        System.assertNotEquals(null, testNote.Id);
        
        Test.setCreatedDate(testAccount.Id, DateTime.now().addMonths(-6));
        Test.setCreatedDate(testNote.Id, DateTime.now().addMonths(-6));
        
        Test.startTest();
        
        System.assert([SELECT COUNT() FROM Note] > 0);
        
        Test.stopTest();
	}
}

The above code will generate the exception:
System.NoDataFoundException: The sObject with the ID 00261000003I5rmAAC isn’t part of this transaction. Provide the ID of an sObject that this test method created.

With a stack trace of:
Class.System.Test.setCreatedDate: line 81, column 1
Class.NoteCleanUp_Test.CleanUp_Test: line 25, column 1

I've also posted this on the salesforce stackexchange network, which you can view here: http://salesforce.stackexchange.com/questions/117473

I'd really like either someone to confirm that yes, this is in fact a bug, or for someone to point out a error in the above code to allow me to write a test class without using a workaround (such as those specified on the linked stackexchange question).