Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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
}
share|improve this answer
    
quick reply! Why would the record be updated if there are no values that are changing? seems counter intuitive to do this! –  Bartley Jul 2 at 8:43
    
Upserts 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 –  Mohith Shrivastava Jul 2 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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