I have a map Map<Id, String>.. I need to change the keys as values and values as keys.. Finally that map will be looking like this---> Map<String, Id>.. How to do this??
Please find below the script to convert a map as per your requirement :
Map<Id,String> existingMap = new Map<Id,String>();
//Assuming that your existingMap is already populated with values
Map<String,Id> updatedMap = new Map<String,Id>();
for(Id KeyValue : existingMap.keySet()){
updatedMap.put(existingMap.get(keyValue),keyValue);
}
//Now you have your new Map updatedMap with your required values.
Please find below the script to convert a map as per your requirement :
Map<Id,String> existingMap = new Map<Id,String>();
//Assuming that your existingMap is already populated with values
Map<String,Id> updatedMap = new Map<String,Id>();
for(Id KeyValue : existingMap.keySet()){
updatedMap.put(existingMap.get(keyValue),keyValue);
}
//Now you have your new Map updatedMap with your required values.
Please find below the script to convert a map as per your requirement :
Let me know if you need more help.
Regards,
Abhishek
All Answers
Please find below the script to convert a map as per your requirement :
Let me know if you need more help.
Regards,
Abhishek
Thank you for your help.. It's working.
Thanks,
Vignesh P