1

I am accessing dynamics CRM data via fetchxml in c#. When I try to execute the following query I am getting below error.

AggregateQueryRecordLimit exceeded. Cannot perform this operation.

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'>
  <entity name='productclass'>
     <attribute name='classificationidid' groupby='true' alias='classidid'/>
     <attribute name='productidid' aggregate='count' alias='ProductCount' />
      <filter type='and'>
       <condition attribute='classidid' operator='in'>" + cIds + @"</condition>
      </filter>
  </entity>

How to resolve this?

2 Answers2

1

This is due to the fact that the entity productclass contains more records than the current limit in the AggregateQueryRecordLimit setting.

You can change this by using the powershell extensions described here: http://msdn.microsoft.com/en-us/library/2a4061cd-e6b4-4672-8c44-20a27c523718

A complete list of settings is available at http://msdn.microsoft.com/en-us/library/gg334634.aspx Remember though that changing this setting could affect performance.

Jonas Rapp
  • 514
  • 2
  • 9
0

CRM is trying to save itself from choking on a disproportionate amount of data.

What I'd suggest as an attempt at optimizing the process would be to run multiple queries, one for each element of cIds (thus switching from in to eq operator, IIRC). You'll end up with one result set for each element, which you'll be able to merge in code (this is simple with LINQ).

Another suggestion I have is for you to upgrade the CRM: in the latest versions you have Rollup Fields which are designed exactly for doing aggregations on related records.

Alex
  • 23,004
  • 4
  • 39
  • 73