You need to sign in to do that
Don't have an account?
Need some SOQL help with aggregate, will give kudos
First problem, when I enter the "Having" statement in soql the Force.com Explorer freezes up.
Second problem, When I run it without the "Having" and with a formula field other than ProductId__c this query runs successfully but not as desired.
When I use other formula fields to summorize by like Product_Name__c which is another formula field this query runs just fine but again without the having and the product id it doesn't work as desired.
This is the formula fields definition: PricebookEntry.Product2Id - on the OpportunityLineItem object.
Below is the query with a id hard coded for testing purposes in the Force.com Explorer.
select ProductId__c ,sum(Quantity) Quantity From OpportunityLineItem Where (Classification__c = 'Software' or Classification__c = 'Professional Services' or Classification__c = 'Bundle (SW w/ HW)') and Case_Id__c = '5007000000LcHVP' Group By ProductId__c Having sum(Quantity) > 1
I will give kudos to anyone that has an idea as to where I've gone wrong.
Thank you,
Steve Laycock
Follow this usecase:
To know more about AggregateResult : http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_query_aggregateresult.htm
(Mark this as solution and hit kudos if it helps)
All Answers
use workbench : https://workbench.developerforce.com/
That’s awesome I didn’t know about the work bench!
One issue though, When I group by
select
Product_Name__c
,max(ProductId__c) ProductId
,sum(Quantity) QuantitySum
From
OpportunityLineItem
Where
(Classification__c = 'Software'
or Classification__c = 'Professional Services'
or Classification__c = 'Bundle (SW w/ HW)')
and Case_Id__c = '5007000000LcHVP'
Group By
Product_Name__c
Having
sum(Quantity) > 0
The third column doesn’t render a name in the workbench result set, it just says "Unknown_Field__1".
Any ideas?
Please let me know what you think can be done to address the naming of the third column please?
Thanks soo much, I really appreciate the introduction to the workbench!
Steve
It always shows name like "Unknown_Field__1" for aggregate field.
if there are two aggregate fields then it will show "Unknown_Field__1" and "Unknown_Field__2".
Ok one last question then you will get credit for the solution as well.....
How do I referance the field in apex, my exp is that if the field wasn't given a name in the query then it would appear like expr0, expr1 etc.....
That said, can you easily tell me how I access the "Unknown_Field__1" like columns to be used in apex code later?
Thanks again,
Steve
Follow this usecase:
To know more about AggregateResult : http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_query_aggregateresult.htm
(Mark this as solution and hit kudos if it helps)