web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Problem LINQ

(0) ShareShare
ReportReport
Posted on by 1,067

Hi all,

I'm having a problem in a Plugin and it's related to a LINQ query that I'm trying to do, the code throwing the error is the next:

//'List' object is an Array of records of a Custom Entity, in this case it has 675 Record Objects and only 1 is Active

//In the line below I'm trying to retrieve all Account Id's from the records contained in 'List'. I was debugging the code and all objects has pwc_AccountId.Id as a property

  var test = List.Select(bp => bp.pwc_AccountId.Id).ToList();

The error that I'm getting is:

Object reference not set to an instance of an object

I don't really understand why I'm getting this error, as long as I can see there's no Null or empty object in that line code.

Do you guys know what could be the problem here?

Thanks in advance!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi Crm user,

    You'll get that error if an item in your list doesn't have an account Id. Update it to:

    var test = List.Where(bp => bp.pwc_AccountId != null).Select(bp => bp.pwc_AccountId.Id).ToList();

    and you'll be good to go.

    Hope this helps! I'd appreciate if you'd mark this as a Verified answer.

    Thanks,

     Aiden

  • EnriqueMdz Profile Picture
    1,067 on at

    As always, thanks a lot Aiden!

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

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans