If you take a look into this issue
Duplicate id in list: 003E000001YDH1jIAH
I have provide an answer of using set<Sobject>
instead using list<Sobject>
i.e.
if( !contacts.values().isEmpty() ){
set<Contact> setContacts = new set<Contact>();
for( Contact objCon : contacts.values() ){
if(!setContacts.contains(objCon)){
setContacts.add( objCon );
}
}
update new list<Contact>(setContacts);
}
even if(!setContacts.contains(objCon))
is not needed
if( !contacts.values().isEmpty() ){
set<Contact> setContacts = new set<Contact>();
for( Contact objCon : contacts.values() ){
setContacts.add( objCon );
}
update new list<Contact>(setContacts);
}
So is there any condition/use case where this answer might fail?