3

I have this Apex SOQL query:

Map<Id, AggregateResult> results = new Map<Id, AggregateResult>([
    select accountid id, min(id), min(Partner_Admin_Sequence_Number__c) Integer 
    from Contact
    where AccountId IN:deactconacctSet and Contact_Status__c ='Active' and (Partner_Admin_Sequence_Number__c !=null and Partner_Admin_Sequence_Number__c!=0)  group by accountid
    ]);
5
  • I already had this issue, but I solved doing the aggregate thru a loop.
    – m Peixoto
    Commented Dec 19, 2018 at 9:22
  • Can you try accountid Id make I in uppercase? Commented Dec 19, 2018 at 9:25
  • Now it is throwing another error:-System.SObjectException: Invalid field accountid for AggregateResult: () Commented Dec 19, 2018 at 9:28
  • @monigangireddy can you also try AccountId Commented Dec 19, 2018 at 9:32
  • Running a MIN() on IDs? what is the purpose of this? .. just wondering.. Commented Dec 19, 2018 at 9:33

1 Answer 1

4

If your deactconacctSet includes a null then accountId (and so its alias idused in the Map constructor) could be null. Add an additional AccountId != null to avoid that:

Map<Id, AggregateResult> results = new Map<Id, AggregateResult>([
    select accountid id, min(id), min(Partner_Admin_Sequence_Number__c) Integer 
    from Contact
    where AccountId IN:deactconacctSet
    and AccountId != null
    and Contact_Status__c ='Active'
    and (Partner_Admin_Sequence_Number__c !=null and Partner_Admin_Sequence_Number__c!=0)  
    group by accountid
]);

You must log in to answer this question.

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