You need to sign in to do that
Don't have an account?
Satya Prakash 11
How to update List containing Duplicate values
Hello All,
Can anyone tell me how to update a list which contains Duplicate values. As we know that list can hold duplicate values but will not update if it contains duplicate values.
I tried to convert the list to Set or Map to hold unique values but the problem is we cannot perform DML operation on Set ot Map.
Any help is highly appreciated!
Can anyone tell me how to update a list which contains Duplicate values. As we know that list can hold duplicate values but will not update if it contains duplicate values.
I tried to convert the list to Set or Map to hold unique values but the problem is we cannot perform DML operation on Set ot Map.
Any help is highly appreciated!
Lets suppose your list is of type contact
List<Contact> lstContacts //This list has duplicates
Use Map
You can use Map instead of list whenever you think there is a possibility of duplicates. and update its values();
Regards,
Bhanu Mahesh
All Answers
1) Create a new list for dml operation
2) create a set to hold list of id
3) Iterate the duplicate list
4) in the loop check if the set of id has the id. add to new list only if id does not exists
something similar to this.
2)then dml statement: update mapUniqueObjects.values();
Lets suppose your list is of type contact
List<Contact> lstContacts //This list has duplicates
Use Map
You can use Map instead of list whenever you think there is a possibility of duplicates. and update its values();
Regards,
Bhanu Mahesh