Skip to main content
Anupama Ramanujan (TCS) 님이 #Apex에 질문했습니다
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개
  1. 2017년 6월 8일 오전 10:28
    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..