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
JBabuJBabu 

apex class test data - Issue

Hi,

 

I have a requirement where I need to display opportunities which are not worked upon for more than 15 days.

I need to show them.

I have created the class.

 

But for test class, I am facing an issue. If I insert test data in to the opportunity object. The last modified date would be the current date.

So there wont be any records which are satistying my criterion (without action for more than 15 days).

And code coverage is not happening properly.

Also "LastModifiedDate" field is not updateable.

Moreover if query the system for data without creating test data, we might not have any opportunities without any activity for more than 15 days.

 

Please suggest me if any one knows any means to tackle this issue.

 

Thanks,

JBabu.

 

Best Answer chosen by Admin (Salesforce Developers) 
Abhay AroraAbhay Arora

For this you can have some formula field which can have same as lastmodified date and use that field in your test class.

 

Please mark this as solved if above is what you need

All Answers

Abhay AroraAbhay Arora

For this you can have some formula field which can have same as lastmodified date and use that field in your test class.

 

Please mark this as solved if above is what you need

This was selected as the best answer
JBabuJBabu

Thanks a lot Abhay.

Just wanted to know if there could any possible solution without having to create new field.

 

Thanks,

JBabu.

Abhay AroraAbhay Arora

Hi

 

The thing is we can not change system fields nor we can have any such dataso for code covarege we need to do this kind of workaround

JBabuJBabu

Ok, thank you Abhay.