Tuesday, October 30, 2007

Object reference not set to an instance of an object

When coding callouts:

string qualifiedStatus = opportunity.new_qualifiedstatus.Value.ToString();

new_qualifiedstatus is a picklist. If we haven't selected any value from that picklist we will get a null reference exception (not an empty or null string). So the right way to assign this would be:

if(opportunity.new_qualifiedstatus != null)
{
string qualifiedStatus = opportunity.new_qualifiedstatus.Value.ToString();
}

No comments: