Test.setCreatedDate() does not work for Note object
Last updated 2022-02-10 ·Reference W-3056075 ·Reported By 1 users
Summary
Test run with setCreatedDate on "Note" entity fails with a datanotfound exception.
Error message: System.NoDataFoundException: The sObject with the ID 0027000000VBxllAAD isn’t part of this transaction. Provide the ID of an sObject that this test method created.
Repro
1. Create a simple test class (Test1) with the following code
@IsTest
public class Test1 {
@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();
}
}
2. Run the test class and observe that it fails with System.NoDataFoundException: The sObject with the ID 0027000000VBxllAAD isn’t part of this transaction. Provide the ID of an sObject that this test method created.
Workaround
N/A
Reported By (1)
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.