1

I have a query onto the OpportunityLineItem table.

AggregateResult[] OppLineItemsPlays = [select OpportunityId, PricebookEntry.Product2.Play__c, COUNT(id) 
                                            from OpportunityLineItem 
                                            where OpportunityId in: oppid
                                            group by OpportunityId, PricebookEntry.Product2.Play__c];
        System.debug('\n ------------------->OppLineItemsPlays = ' + OppLineItemsPlays);

I expected results like:

Count=1, OpportunityId=1, Play__c=RED}, 
Count=2, OpportunityId=1, Play__c=WHITE}, 
Count=1, OpportunityId=2, Play__c=WHITE},
Count=2, OpportunityId=2, Play__c=BLACK}  
Count=2, OpportunityId=3, Play__c=RED},  
Count=2, OpportunityId=4, Play__c=RED}, 
Count=2, OpportunityId=4, Play__c=BLACK}

So that I get the number of OLIs that have the same Playcode for each opportunity

What I get is:

AggregateResult:{expr0=3, OpportunityId=1, Play__c=RED, 
AggregateResult:{expr0=2, OpportunityId=2, Play__c=WHITE}, 
AggregateResult:{expr0=2, OpportunityId=4, Play__c=BLACK}

I was thinking that the GROUP BY would give me the equivalent of a dual Primary key... I want to know how many OLIs for OPP1 have Play = RED, then push that to the Opportunity. (I know a rollup would work - but we've run out and there are no more to be had)

These are batch loaded / updated so the current code works ok when working with a single opportunity no matter how many Products are added. When >1 opportunity is added the Aggregate fails

2
  • This is not the normal behaviour. I tried it out to be sure and it works fine for me. What fieldtype is Play__c? Mar 27, 2014 at 12:39
  • It's a picklist. I rewrote it and it seems to work now. I am going back through the data to see if I did anything wrong on the analysis
    – SeanGorman
    Mar 28, 2014 at 15:42

0

You must log in to answer this question.

Browse other questions tagged .