+ Start a Discussion
Developer BaseDeveloper Base 

Apex testing class - creating records with a custom LastModifiedDate value

Trying to create data with a custom LastModifiedDate value for testing purpose. So far these things I've tried don't work:
  1. Using Test.loadData - although Salesforce provided us with information about setting custom value of LastModifiedDate, this does not seem to work even when following the tutorial. Link: https://help.salesforce.com/articleView?id=000332070&type=1&mode=1 (https://help.salesforce.com/articleView?id=000332070&type=1&mode=1)
  2. Using JSON.deserialize - also does not work - copied the sample code and tried the same method, it shows errors. Link: https://help.salesforce.com/articleView?id=000332070&type=1&mode=1 (https://help.salesforce.com/articleView?id=000332070&type=1&mode=1)
  3. Setting CratedDate through Test.setCreatedDate(recordId, createdDatetime) method - I hoped the LastModifiedBy field would have changed with it, it does not.

Is there any other WORKING way how to set LastModifiedDate of a record? 
AnudeepAnudeep (Salesforce Developers) 
What is the output when you run the tests?
Developer BaseDeveloper Base
11:38:44:028 EXCEPTION_THROWN [13]|System.DmlException: Update failed. First exception on row 0 with id 500E0000002nH2fIAE; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []

Happens on update. Does it work for you?