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
BrianDunzweilerBrianDunzweiler 

Test Class FIELD_INTEGRITY_EXCEPTION on Last Modified Date

I wrote a test class that passed without issue in one sandbox environment (test), but fails in the next environment (UAT).  I did a file compare on the affected class and the test class and found no differences.  It fails on the insert call:

 

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Last Modified Date(Mon Jul 26 01:48:35 GMT 2010) before Create Date(Mon Jul 26 01:48:37 GMT 2010).: [LastModifiedDate]

 

I found reference to this type of error in the data migration area, but not in Apex code.  Any ideas as to what may cause this?

 

Thanks,

 

Brian

Pradeep_NavatarPradeep_Navatar

In my opinion this type of Error will result if the Last Modified Date for a record in the Data is less then Created Date. This Error can be easily fixed by tight Validation checks on the Data and by changing the Last Modified Date to be greater or equal to the Created Date. Also try using validation rules on the object for last modifed date.

Did this answer your question? if so, please mark it solved.

BrianDunzweilerBrianDunzweiler

Pradeep,

Thanks for the reply.  I currently have an ticket open with salesforce support as I think the error is a combination of conditions that exists in our sandbox.  The class being tested uses the clone method which should not be an issue. However, we currently have a setting enabled that allows the system administrator to modify the audit fields (lastmoddate/id, etc) because of data migration activities.  We believe that the clone method is exposing the audit fields since the test is being run under system admin privileges and is therefore causing the issue, i.e. that the last modified date is being copied from the current object into the clone object, but is not being updated during the insert.  So the create date for the new clone is greater than the last modified date from the original object.  I will update this thread once we hear back from support.

Brian

Edgars Everts 5Edgars Everts 5
Hi, Brian!
Have you got an answer from support, or is it still pending!
Would like to know have you any luck to solve this issue!?

I have the similar issue, when using Test.setCreatedDate (objectID, date). (and date = Datetime.now();)
System.DmlException: Update failed. First exception on row 1 with id a0U9E000002MMjyUAG; first error: FIELD_INTEGRITY_EXCEPTION, Last Modified Date(Sat Sep 09 19:49:30 GMT 2017) before Create Date(Sun Sep 10 19:49:30 GMT 2017).: [LastModifiedDate]

Not aware can I modify :LastModifiedDate, but I woul like to set it less CreatedDate.

but scenario is 
1. create a list , do insert
2. assign different created date to list elements.
3. do list update 
// some logic on records based on created date.

So since we want make created date historic, we set yesterday date for some records, and some future dates for other records, and I guess here it comes, LastModified < CreatedDate
so Future Lat Modified Date = Sept 9 , but future created date = Sept 10, that's should be the root cause.

Any idea how to wrok-a-round "last modified date".

One solution set all created dates different but less that today. e.g. Sept 5 , Sept 7 , Sep 8. (all will be valid created dates for last modified Sept 9).

Thanks for your time!
Kind regards
Edgars Everts 5Edgars Everts 5
Hi, Brian!

For our org, and logic built on CreatedDate check this is working work-a-round:
first List created:
List[0].Name = 'Some One Name';
List[1].Name = 'Some Other Name';
insert List;
initial version (worked before new API 41)
Datetime dateYesterday    = Datetime.now().addDays(-1);
Datetime dateTomorrow     = Datetime.now().addDays(1);
modified to:       
Datetime dateYesterday    = Datetime.now().addDays(-9);
Datetime dateTomorrow     = Datetime.now().addDays(-7);
Date usage:
Test.setCreatedDate(List[0].Id, dateYesterday);
Test.setCreatedDate(List[1].Id, dateTomorrow);
update List;

But still wondering if this deploy issue come with API 41 version, or there was other cause.
Because this code was deployed previously successful.

Kind regards