function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prakher Chaturvedi 2Prakher Chaturvedi 2 

SystemModStamp coverage in Apex class

I have a class which filters query on SystemModStamp < Yesterday.

I want to cover this query in test class by creating record in test class whose SystemModStamp is older than yesterday.

I have tried on Json.deserialize method and Test.LoadData method both do not work well for systemModStamp. 

Dushyant SonwarDushyant Sonwar

Prakher,

You can use Test.createdDate method in salesforce.
https://developer.salesforce.com/docs/atlas.en-us.234.0.apexref.meta/apexref/apex_methods_system_test.htm

Example is shown below

@isTest 
private class SetCreatedDateTest {
    static testMethod void testSetCreatedDate() {
        Account a = new Account(name='myAccount');
        insert a;
        Test.setCreatedDate(a.Id, DateTime.newInstance(2012,12,12));
        Test.startTest();
        Account myAccount = [SELECT Id, Name, CreatedDate FROM Account 
                             WHERE Name ='myAccount' limit 1];
        System.assertEquals(myAccount.CreatedDate, DateTime.newInstance(2012,12,12));
        Test.stopTest();
    }
}