We are querying max value among certain field values of same data type from an object. we cant form perfect query . could anyone help to get perfect query.
-
It'd be easier to answer if you can share your current query and what output you'd like. Adding more details and context in your question will help us help you! :)– Samuel De RyckeCommented Jun 2, 2014 at 13:57
-
Oppty= [select MAAmount), AccountID from Opportunity where AccountID=:Acc.Id group By AccountID]; HI this is the query we have used . Our scenario is to get the max value among the set of field's.– SalesforcesupportCommented Jun 2, 2014 at 15:28
Add a comment
|
1 Answer
I would look into Aggregate Results queries. Without knowing too much about your requirements , here is a simple example below
list<aggregateResult> aggResults = [SELECT MAX(Amount)myMax FROM Opportunity];
System.debug('Max is: ' + aggResults[0].get('myMax'));
For more on AggregateResult queries, see the links below
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_agg_fns.htm
http://blog.jeffdouglas.com/2010/04/12/using-aggregateresult-in-salesforce-com-soql/