You need to sign in to do that
Don't have an account?
Oliver Jones Rajkumar
Count() Closed Won and Closed Lost in a Single SOQL
Hi All,
Is it possible to build a SOQL query to retrieve/show the count of closed and open opportunities under each accounts? I would to execute this code in the query editor in developer console.
Help and Thanks.
Is it possible to build a SOQL query to retrieve/show the count of closed and open opportunities under each accounts? I would to execute this code in the query editor in developer console.
Help and Thanks.
Create Two Rollup Summary fields on Account Object
1) No of Open Opportunities (Using COUNT() Function )
2) No of Closed Opportunities (Using COUNT() Function )
Then Write an SOQL Query to retrieve No of Open Opportunities & No of Closed Opportunities for an Account.
List<Account> accounts = [SELECT Id,Name,No_of_Open_Opportunities__c,No_of_Closed_Opportunities__c FROM Account];
system.debug('=====No of Accounts=========' + accounts);
Thanks.
All Answers
it can be done using size() fuction of list class here is the sample code.
Now you counts have it all.
Hope this helps :)
Hi Oliver,
Try this one:
Same you can do for Open Opportunities and if you want to result in a single Query, you can add filter with AND operator StageName='Open'
I hope it helps you. Please mark this as best answer if it helps you, so that it will be easy for others to find out easily.
Thanks,
Yogesh Sharma
Create Two Rollup Summary fields on Account Object
1) No of Open Opportunities (Using COUNT() Function )
2) No of Closed Opportunities (Using COUNT() Function )
Then Write an SOQL Query to retrieve No of Open Opportunities & No of Closed Opportunities for an Account.
List<Account> accounts = [SELECT Id,Name,No_of_Open_Opportunities__c,No_of_Closed_Opportunities__c FROM Account];
system.debug('=====No of Accounts=========' + accounts);
Thanks.