Loading

Salesforce CPQ Lookup Price Rule Too Many Query Rows Error

Date de publication: Oct 12, 2026
Description

Quote calculation in Salesforce CPQ (managed package) can fail with a "Too Many Query Rows" error or a heap size error when Lookup Price Rules reference large lookup object tables, or when quotes contain many quote lines. The cause is the way Salesforce CPQ queries lookup records.

How Salesforce CPQ builds the lookup SOQL query

Salesforce limits the total number of SOQL queries that an org can run per transaction, so Salesforce CPQ cannot query the database separately for each quote line. Instead, Salesforce CPQ Lookup Price Rules combine all lookup criteria into one large SOQL query. The query returns every potential match from the lookup object. Salesforce CPQ then loops over the returned records to find the exact match for each quote line and applies the values in the Salesforce CPQ Price Actions.

The query is assembled as follows:

  • SELECT clause: includes every lookup object field referenced in the Lookup Queries and Price Actions.
  • WHERE clause: built from the quote line values. OR logic applies to the possible values within each individual field. AND logic connects the groups of field values.

Example of potential matches

A price rule sets a quote line field to the value of LOField3 (Lookup Object Field 3), based on QLField1 and QLField2 (Quote Line Field 1 and Quote Line Field 2).

Lookup object records:

  1. LOField1 = A | LOField2 = 1 | LOField3 = Apple
  2. LOField1 = A | LOField2 = 2 | LOField3 = Banana
  3. LOField1 = A | LOField2 = 3 | LOField3 = Blueberry
  4. LOField1 = B | LOField2 = 1 | LOField3 = Kiwi
  5. LOField1 = B | LOField2 = 2 | LOField3 = Mango
  6. LOField1 = B | LOField2 = 3 | LOField3 = Orange
  7. LOField1 = C | LOField2 = 1 | LOField3 = Peach
  8. LOField1 = C | LOField2 = 2 | LOField3 = Pear
  9. LOField1 = C | LOField2 = 3 | LOField3 = Strawberry

Quote lines:

  1. QLField1 = A | QLField2 = 1
  2. QLField1 = B | QLField2 = 2

Lookup Queries: QLField1 equals LOField1, and QLField2 equals LOField2.

Price Action: set the quote line field equal to LOField3.

The resulting query is:

SELECT LOField1, LOField2, LOField3 FROM LookupObject WHERE (LOField1 = A OR LOField1 = B) AND (LOField2 = 1 OR LOField2 = 2)

This query selects the three referenced fields and filters on every value that appears across the quote lines. In plain terms, it returns any lookup record whose LOField1 is A or B and whose LOField2 is 1 or 2.

Why the row count multiplies

The query returns four lookup records (1, 2, 4, and 5) for only two quote lines, which is twice the number of records needed. Salesforce CPQ then identifies records 1 and 5 as the exact matches.

Adding a third quote line (QLField1 = C | QLField2 = 3) makes the query return all nine lookup records, three times the number needed. The number of Lookup Price Rules, Lookup Queries, quote lines, and lookup table records can therefore have a multiplicative effect on the total query rows returned and on the heap size of the returned list.

Résolution

The following steps reduce the number of query rows that Salesforce CPQ Lookup Price Rules return and the heap size of the returned list, which prevents the "Too Many Query Rows" and heap size errors during calculation.

How to reduce query rows returned

Reducing any of these four factors lowers the number of rows returned: Lookup Price Rules, Lookup Queries, quote lines, and lookup table records.

  1. Split the large lookup object into multiple smaller lookup objects, grouped by a value that divides the data naturally (for example, region or product family). Each smaller table holds fewer potential matches.
  2. Add Price Conditions to each Lookup Price Rule so that each rule applies only to the quotes or lines that use its lookup table. Each query then searches a smaller pool, and fewer extra records are returned.
  3. Remove Lookup Price Rules and Lookup Queries that are no longer needed. Each removal eliminates a multiplier from the combined query.

Splitting the lookup object adds one or two SOQL queries to the processing. Each of those queries is more precise, so the overall number of rows returned drops.

How to reduce heap size

If a heap size error continues after the number of query rows is reduced, reduce the amount of data held for each returned record.

  1. Review every Salesforce CPQ Price Action that uses the lookup object. Each lookup object field referenced in a Price Action or Lookup Query is added to the SELECT clause and is stored in memory for every returned record.
  2. Remove Price Actions that populate fields that are not needed. Each removed reference shrinks every returned record.
  3. Where several Price Actions pull different fields from the same lookup object, consolidate them so that only required fields are referenced.
  4. Avoid referencing long text fields on the lookup object where a shorter field type serves the same purpose, because long values consume more heap per record.
  5. Recalculate a test quote that previously failed to confirm that the error no longer occurs.
Numéro d’article de la base de connaissances

000383603

 
Chargement
Salesforce Help | Article