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
Anupama Ramanujan 13Anupama Ramanujan 13 

How can we fetch the value from Map based on particular key?

Need to fetch the value from Map based on particular key and assign to a new variable.

If Map is defined like <Id,String> then, want to check if any particular Id is existing in the Map and if it is there in map. The String value for that Id should be assigned to a new String variable. Is it possible to do? If so, how to perform this action.
 
Sam1942Sam1942
Hi Anupama,

Lets say you have Map -  Map<Id, String> AccountIdAndNameMap = new Map<Id, String>();

then you can check like -  AccountIdAndNameMap.containsKey(Id) ; 

It will give you whether perticular id exists in map or not.

if you get value then you can assign it to new String variable.

ex,

String Name ;
if(AccountIdAndNameMap.containsKey(Id)){
    Name = AccountIdAndNameMap.get(Id);
}

I hope it helps you to resolve your query..