Skip to main content
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.

 
1 respuesta
  1. 8 jun 2017, 10:28 a.m.
    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..