Create a map instead of list and finally insert or update the map values.
Sample Code:
Map<Id, Account> mapAccount = new Map<Id, Account>();
for(Account acc : listAccount){
...............
...............
mapAccount.put(acc.Id, acc);
}
update mapAccount.values();
Sample Code:
Map<Id, Account> mapAccount = new Map<Id, Account>();
for(Account acc : listAccount){
...............
...............
mapAccount.put(acc.Id, acc);
}
update mapAccount.values();
Why We need to do all these things.. Simply do like this
ReplyDeleteList Listacc= [select id,name from account];
Set Unique= New Set();
Unique.addall(Listacc);
plz correct me, if i am wrong..
This is also correct!!!
DeleteHi,
DeleteI'd like to one line it
Set Unique = new Set ([select id from Account]);
Or for DML, from a duplicated list:
update (new Map (oppList)).values();
Naore
Correction:
Deleteupdate (new Map (oppToUpdate)).values();
account id always unique what about account name but its not unique so then how to make list of account name to be unique so if use set how to know that the string values are equal then I need to give custom error how please let me know
ReplyDeleteUse Map < String, String > and use containsKey() in map to find whether already the map contains the same name.
DeleteUse Duplicate management to avoid creating duplicate records - http://www.infallibletechie.com/2015/05/duplicate-management-in-salesforce.html