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
Muna Jamous 8Muna Jamous 8 

Allow multiple update of an SF ID in a list using Database.update

I am trying to update the same id in a list mutliple times, is there a way to do that 
List<contact> ConList = new List<contact>();

contact pe = new contact();
pe.id =  '0032900000QsV17';
pe.phone__c= false;
ConList .add(pe);

contact pe2 = new contact ();
pe2.id =  '0032900000QsV17';
pe2.phone__c= true;
ConList .add(pe2);


Database.SaveResult[] srList = Database.update(ConList ,false);
System.debug('srList===' + srList);
Agustin BAgustin B
Hi Muna, yes you can do something like this but it wont be on a bulk:
contact pe = new contact();
pe.id =  '0032900000QsV17';
pe.phone__c= false;
update pe;

pe.phone__c= true;
update pe;

If this solves your issue please mark this answer as correct, it may help others
KtHasNoLimitKtHasNoLimit
Hi Muna,

You can not update the same id in the list multiple times because it gives you the error but there is a way to solve this issue. Instead of creating the different instances of the record update the same instance of the record.
List<contact> ConList = new List<contact>();

contact pe = new contact();
pe.id =  '0032900000QsV17';
pe.phone__c= false;
ConList .add(pe);

for(Contact c : Conlist){
     if(c.id == '0032900000QsV17') {
          c.phone__c = true; 
     }
}

Database.SaveResult[] srList = Database.update(ConList ,false);
System.debug('srList===' + srList);

If this solves your issue please mark this answer as correct.

Thanks,
Kirti Rathod