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

How to avoid saving other records in a custom VF page

Hello everyone, I created a custom list of Event records using a custom controller and Visualforce page. In the list the user can edit an Event but after saving the change, it also changes the last modified date of the other records on the list, even though there was no change to the data. What can I do so that Salesforce will only update the record that was changed?
Below is my current custom controller:
public class EventsMDHomePage{

    public List<Event> eventsToday {get; set;}

    public EventsMDHomePage() {
        eventsToday = [
            FROM Event
            WHERE OwnerId =: UserInfo.getUserId() AND ActivityDate =:
            ORDER BY StartDateTime ASC
            LIMIT 1000];
    public PageReference saveEvents() {
            update eventsToday;
        catch(DmlException ex){
        return null;
VinayVinay (Salesforce Developers) 
Hi Richard,

Hope you query is answered below.

Hi Vinay, thanks for notifying me. I think the solution is correct but do you mind explaining what this part means please:
for(Integer i = 0, s = eventsToday.size(); i < s; i++) {
            if(originalEvents[i] != eventsToday[i]) {