Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Object reference not set to an instance of an object - Error throwing when the list is empty

(0) ShareShare
ReportReport
Posted on by 534

Hi Guys,

When we get the list value has "null"  in the contract class the process get stopped here and throwing the error as "object reference not set to an instance of an object"

code -

If (contract.parmlistId().elements())

Please help me to solve this.

  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: Object reference not set to an instance of an object - Error throwing when the list is empty

    Hi jenifer,

    To check whether list is null or not you can use empty method and then get the elements.

    if(!contract.parmListId().empty())

    Thanks,

    Girish S.

  • Suggested answer
    Mohit Rampal Profile Picture
    12,563 Moderator on at
    RE: Object reference not set to an instance of an object - Error throwing when the list is empty

    Hi Jennifer, This generic error occurs whenever there is null value in the object. Please provide more info on your code or debug your code where you are initializing ListId.

    Also, check if contract is not null.

  • Verified answer
    huijij Profile Picture
    19,811 on at
    RE: Object reference not set to an instance of an object - Error throwing when the list is empty

    Hi jenifer, 

    The error means that you are referring to an object the does not exist or was deleted or cleaned up. It's usually better to avoid a NullReferenceException than to handle it after it occurs. To prevent the error, objects that could be null should be tested for null before being used.

    if (mClass != null)
    {
    // Go ahead and use mClass
    mClass.property = ...
    }
    else
    {
    // Attempting to use mClass here will result in NullReferenceException
    }

  • Adam123 Profile Picture
    534 on at
    RE: Object reference not set to an instance of an object - Error throwing when the list is empty

    whenever the list is empty this validation is getting failed

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 565

#2
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 402 Super User 2025 Season 1

Product updates

Dynamics 365 release plans