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
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