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
Firas Taamallah 18Firas Taamallah 18 

how to assign a Map Value to a string in Apex?

Hello , 

i want to assign a string to Map value  like ; 
String SA =    String.valueOf(emailConfigMap.get(c.EmailConfiguration__c).Email__c) ;
its throwing  a NullPointerException - 
 
AbhinavAbhinav (Salesforce Developers) 
@Firas Please share detailed code 
Maharajan CMaharajan C
Hi Firas,

Always please do the null check before accessing the value from Map.
 
String SA = '';
if(emailConfigMap.containsKey(c.EmailConfiguration__c)){
	SA = String.valueOf(emailConfigMap.get(c.EmailConfiguration__c).Email__c) ;
}

Thanks,
Maharajan.C