You need to sign in to do that
Don't have an account?
Starz26
Use keySet where a List is needed
Greetings,
Just curious if there is a one line way to declare a list and addAll values from a set to that list.
I currently have:
ID[] toDel = New ID[]{};
toDel.addAll(PVtoExternalIDs.keySet());
database.delete(toDel);
I would like to convert the keySet to a list and not have the other tow lines. Kind of like:
database.delete(New ID[]{map.keySet()});
but that does not work obviously....
Unfortunately there isn't - set isn't supported as a parameter to the list constructor, so you have to instantiate then add all. If the map values are the sobjects to delete you can pass that as the parameter to the delete call.
All Answers
Is it necessary to be on liner ??
Otherwise the approach is very simple. Iterate over the set and copy all the elements in the list.
And then perform the delete operation.
Unfortunately there isn't - set isn't supported as a parameter to the list constructor, so you have to instantiate then add all. If the map values are the sobjects to delete you can pass that as the parameter to the delete call.
Thanks to all who responded.
1. I have a Map that uses an external ID (not unique) as the Key and the ID of the record as the Values as Set<ID>
2. I need to find all records in the keySet() that have the ID in the values() (Set<ID>);
Since I cannot use a Set in database.delete, I need it in a list. Would have been nice not to have to itenerate over the set...just adds more code.
Since it is not possible, moving on.....