D365 Error

Dynamics 365 Error #2 Object reference not set to an instance of an object

As Microsoft Dynamics developer, We came across this error regularly in our day to day life.

Problem Description:-  “Object reference not set to an instance of an object”
There could be multiple reason we come across this issue. However below are few things which can be looked at to fix this issue and save your time.
  • Entity Attribute/Field does not contains data or the value is null. Say you are trying to get FirstName from Lead Entity attribute and splitting the value into two string based on some parameter.

    string[] strArray=objLead[“firstname”].split(‘,’);

    This particulat line of code will throw Object Reference error if FirstName is null. To avoid this, We can add check condition as below.

    if(objLead.Attributes.Contains(firstname) && objLead[“firstname”]!=null);
    string[] strArray=objLead[“firstname”].split(‘,’);

    Other way to fix this is to use objLead.GetAttributeValue<string>(“firstname”); Then check for null.

    Hope this will help!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s