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
AbAb 

null pointer exception for a map

Hello,

I am getting a null pointer exception in below code.
how can i put a check on below code to check if it is null or not
public static Map<String, Map<Id, RecordType>> rtTemp = new Map<String, Map<Id, RecordType>>(), 
public SObjectType oName;
public static final String RT_ID = 'rtTemp';

public void setSObjectType(SObjectType objT) {
   this.oName = objT;
}

function()
{      
	Map<Id, RecordType> rtMap = rtTemp.get(String.valueOf(Account.SObjectType));

	String rtTemp = (String) obj.get(RT_ID);
	
	String rtDName = rtMap.get(rtTemp).DeveloperName;	 // Null pointer exception
}
thank you for suggestion
 
Best Answer chosen by Ab
ShirishaShirisha (Salesforce Developers) 
Hi Sandrine,

Greetings!

You can either check for the size of the variable or list which you suspect is returning as null before executing the code or use exception handling as suggested here.

https://help.salesforce.com/articleView?id=000327918&type=1&mode=1

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi Sandrine,

Greetings!

You can either check for the size of the variable or list which you suspect is returning as null before executing the code or use exception handling as suggested here.

https://help.salesforce.com/articleView?id=000327918&type=1&mode=1

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
This was selected as the best answer
AnudeepAnudeep (Salesforce Developers)