function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nisha Babu 8Nisha Babu 8 

How to get the value for an field from the keySet(). I don't want the value for all fields but value for some fields in the object. And I have to store the selected key and value to another map

Hi

How to get the value for an field from the keySet().
I don't want the value for all fields but  value for some fields in the object.
And I have to store the selected key and value to another map
William TranWilliam Tran
Loop through the keyset and grab whatever matches your criteria.

Code:
                for (String key : someMap.keySet()) {
                        PUT YOUR LOGIC HERE using:(key + " = " + someMap.get(key));
                }

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you. 

Thx
Nisha Babu 8Nisha Babu 8
Hi Willam,

Thank You for the help.
I have to get the values of the fields.
And have to store it in a new map.
Could u plz write how to construct a new map.
And add the key and value to the new map.

Regards,
  Nisha
sandhya reddy 10sandhya reddy 10
Hi Nisha,

Below is the things which u can do with maps which may help you.

Map<Integer, String> m = new Map<Integer, String>(); // Define a new map
m.put(1, 'First entry');                  // Insert a new key-value pair in the map
m.put(2, 'Second entry');                  // Insert a new key-value pair in the map
System.assert(m.containsKey(1));  // Assert that the map contains a key
String value = m.get(2);               // Retrieve a value, given a particular key
System.assertEquals('Second entry', value);
Set<Integer> s = m.keySet();       // Return a set that contains all of the keys in the map

If this solves your problem please mark it as solution(Best Answer)

Thanks
Sandhya Reddy