You need to sign in to do that
Don't have an account?

get top 5 accounts based on sum of related opportunity field data in salesforce
Hi guys,
I have custom opportunity field named Total_Amount__c.
I need to get Top 5 accounts with opportunities based on Total Amount.
Need to code above(not in reports)
Note: Consider if an account have 5 opps, then the sum of 5 opp fields need to be taken into consideration.
Thanks in advance,
I have custom opportunity field named Total_Amount__c.
I need to get Top 5 accounts with opportunities based on Total Amount.
Need to code above(not in reports)
Note: Consider if an account have 5 opps, then the sum of 5 opp fields need to be taken into consideration.
Thanks in advance,
i created one rollup summary field on account for opportunity called total_opportunity_amount__c
You should get top 5 accounts based on sum of related opportunity field using the following query
List<AggregateResult> aggregateResults = [SELECT AccountId, SUM(Total_Amount__c) FROM Opportunity GROUP BY AccountId ORDER BY SUM(Total_Amount__c) DESC LIMIT 5];
Thanks,
Thiyagarajan Selvaraj