I'm trying to make a test class for an Apex class that runs a report and add functionality for it (send some emails and stuff). The problem is that I need to add records (contacts) for that report to work with, but I cannot make them fit the conditions required in the report.

The report conditions are: checkbox = TRUE AND edit date = TODAY

In the testMethod I do:

Contact c = new Contact(checkbox__c = FALSE);
insert c;
c.checkbox__c = TRUE;
update c;
System.debug('>>'+c.checkbox__c+', '+c.LastModifiedDate)
// run the report...

And this prints in the log:


The checkbox its set to TRUE correctly but he LastModifiedDate is set to null when it was updated just now. The report runs correctly but says that it have not records to show and end the execution.

Thanks for the help.


You have to query back for the record.

Contact record = new Contact(SomeField__c=someValue);
insert record;

record.SomeField__c = otherValue;
update record;

record = [SELECT SomeField__c, LastModifiedDate FROM Contact WHERE Id = :record.id];
system.assertNotEquals(null, record.LastModifiedDate, 'This record has been modified');
  • Thanks, that works perfectly. But, do you have any ideas why the report doesn't find any results although the contact was modified today and has the checkbox set to true? Anyways, thanks again. – mbayon Feb 4 at 7:31
  • 1
    That may be worth asking separately. Your question above does not really contain sufficient detail to answer it. – Adrian Larson Feb 4 at 10:09
  • You are absolutely right, so I just made it :) – mbayon Feb 4 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.