1

I'm trying to query the Products that has more than 3 Quantity

Below is my query:

Set<Id> extras = new Map<Id, AggregateResult>([
    SELECT Product2Id
    FROM OpportunityLineItem
    WHERE Product2Id In: oppIds
    GROUP BY Product2Id
    HAVING SUM(quantity) > 3
]).keySet();

Any ideas on why I'm having

FATAL_ERROR|System.ListException: Row with null Id at index: 0

1 Answer 1

4

When using an AggregateResult query with the Map<Id, AggregateResult> constructor, you need to alias the field to the specific alias Id (case-sensitive):

Set<Id> extras = new Map<Id, AggregateResult>([
    SELECT Product2Id Id
    FROM OpportunityLineItem
    WHERE Product2Id In: oppIds
    GROUP BY Product2Id
    HAVING SUM(quantity) > 3
]).keySet();
1
  • Such a big help! Thank you so much for the additional knowledge :) Commented Nov 8, 2019 at 1:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .