SOQL クエリでは以下の 2 つの異なるシナリオにおいて、"Aggregate query has too many rows for direct assignment" という例外が発生します。
シナリオ 1: サブクエリの結果が 200 行を超える場合
SOQL 集計クエリ内のサブセレクトで 200 行を超える結果が返された場合、その結果を変数に直接代入しようとすると、Salesforce はこの例外を発生させます。これを解決するには、直接代入の代わりに FOR ループを使用して結果を順に処理してください。
シナリオ 2: サブセレクトの結果が 200 行未満の場合 — ロングテキストまたはリッチテキスト項目
すべてのサブセレクトが 200 行未満を返しているにもかかわらず例外が発生する場合は、SOQL クエリでロングテキストエリア項目またはリッチテキストエリア項目が選択されていることが原因である可能性があります。
これらのフィールドタイプは、大量のデータを格納することができます。Salesforceでは、過度なメモリ消費を防ぐため、多数の大型オブジェクト(LOB)フィールドを参照するクエリに対して、追加のメモリ制限を適用しています。この制限により、サブセレクトの実効行数が 200 行未満に制限され、実際の行数が少ないように見えても例外が発生する可能性があります。
この例外を解決するには、SOQL クエリのメモリ使用量を削減してください。
サブクエリの結果が実際に 200 行を超える場合(シナリオ 1)、結果を List 変数に直接代入するのではなく、FOR ループ を使用して結果を反復処理するようにクエリをリファクタリングしてください。
000381135

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.