If I run an upsert
on a theoretical 100 records, all of which already exist in Salesforce, but only 4 of which have changed field values, will the last modified date
for every record be set to the date that the upsert
was run as opposed to the date that the record was last changed during the upsert, resulting in 96 record not having their last modified date changed. My understanding is that upsert only change the last modified date of the records that had changed field values.
2 Answers
The last modified date of the every record will definitely change ,since an update of record will eventually happen even if field values are not changed .
If you need to explicitly code such scenarios ,i would definitely recommend to do an explicit update and update only those records whose field values have changed .
if(previous_value!=new-Value){
//List for update
}else{
//List for insert
}
-
1quick reply! Why would the record be updated if there are no values that are changing? seems counter intuitive to do this!– BartleyJul 2, 2014 at 8:43
-
2Upserts or update work even without any change on the record .Try querying an account and do an update with no change .You will see update will still run and last modified date changed .So a DML statement is a stament that will execute irrespective of any change in the field level Jul 2, 2014 at 8:50
Running this in Dev Console updates the lastmodifieddate of the record:
Course__c c = new Course__c(id='a0C11000001W4s1EAC');
upsert c;
So yes, even without updating any values the record is updated. Note: This will run triggers and workflows as well.