In Spring ‘10, Salesforce released new Apex functionality for total functions in SOQL. These queries return an AggregateResult object. Utilize aggregate functions in a Group…
SELECT CampaignId, AVG(Amount) FROM Opportunity GROUP BY CampaignId
USING COUNT( ): SELECT COUNT( ) FROM opportunity WHERE Name LIKE ‘a%’ USING COUNT(fieldName): SELECT COUNT(Id) FROM opportunity WHERE Name LIKE ‘a%’
SELECT COUNT_DISTINCT(Company) FROM LeadOne thing to be mindful of is that the count() function does not return an AggregateResult object. The coming about query result estimate field returns the number of columns
integer rows = [select count() from contact]; System.debug('rows: ' + rows);
SELECT MIN(CreatedDate), FirstName, LastName FROM Account GROUP BY FirstName, LastNameIn the event that you employ the MIN() or MAX() functions on a picklist field, the function uses the sort order of the picklist values rather than in sequential order arrange
SELECT Name, MAX(BudgetedCost) FROM Campaign GROUP BY NameCheck out another amazing blog by Ayush here: How To Lock Records In Salesforce | The Complete Guide
SELECT SUM(Amount) FROM Opportunity WHERE IsChecked = Tri AND Probability > 70Examples 1:-
List<aggregateResult> LstAR = [select leadsource, count(name) total, count(state) from lead group by leadsource ]; for (AggregateResult ar : LstAR ) System.debug(ar.get('leadsource')+'-'+ar.get('total')+'-'+ar.get('expr0'));Examples 2:-
AggregateResult ar = [SELECT AccountId, AVG(Amount) Avg FROM AccountId]; Object avgAmount = agResults.get(‘Average’);Note:- You can’t utilize a Limit clause in a query that employs aggregate work. The taking after query is invalid: Examples 3:-
SELECT MAX(CreatedDate) from Account limit 1
There was a problem reporting this post.
Please confirm you want to block this member.
You will no longer be able to:
Please note: This action will also remove this member from your connections and send a report to the site admin. Please allow a few minutes for this process to complete.