+ Start a Discussion
SteveSFDevSteveSFDev 

NullReferenceException errors

Hi

I'm having problems handling NullReferenceException errors. This occurs when a contact first or last name is blank or null.

 

I tried using the following code to deal with these scenarios but it does not seem  to solve the problem

String FirstName = (contact.FirstName.ToString() != null) ? contact.FirstName.ToString() : "";

catch (NullReferenceException Nullex) {

LogError(Nullex.InnerException.ToString());

}

Either of this code line work

SuperfellSuperfell
String FirstName = contact.FirstName == null ? "" : contact.FirstName;
SteveSFDevSteveSFDev
Thanks that works