Dynamics 365 Error #2 Object reference not set to an instance of an object
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!
Comments
Post a Comment