function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Steven HoughtalenSteven Houghtalen 

query to find out the number of groups

I have a custom object - services log, where I log every service performed for every client.  I need to form a query to determine how many clients were served during a defined period. This query will be used in conjuction with Conga Composer to produce a report so I can't compliment the query with some apex code. Can anyone help me define a query that would do this?  I am stumped. 
rajat Maheshwari 6rajat Maheshwari 6

Hi Steven,

I am assuming, services log is parent object which should have fields (ServiceStartDate) and (ServiceEndDate)

Client (Account/contact) is child object 

Query must be like : - 

List<Client> clnt_List = [Select Id,name from client where Service_Log__r.ServiceStartDate >: 2017-01-01T00:00:00Z and ServiceLogAPIName__r.ServiceEndDate :< 2017-02-09T00:00:00Z]

 

Here lookupRelationShip field : Service_Log__c

 

please let me know in case of any help or issue.

Thanks

 

Steven HoughtalenSteven Houghtalen
Hi Rajat,  thank you for your reply.  ServiceLog is not the parent of Client.  I should have stated the relationships.  The query needs to result in a single integer and not an array. I can group by the id of the clients but I can't seem to find a way to get a count of the number of groups.
rajat Maheshwari 6rajat Maheshwari 6

Steven,

you can use aggregate query for finding the count of number of groups, just like in below sample code snippet - 

I am taking account as a parent object and opportunity as a child object and I want to find the number of opportunities associated with account - 

for(AggregateQuery agg : [Select AccountId, Count(Id) from Opportunity group by AccountId])

{
    Decimal dec = (Double)agg.get('expr0');
}
 

 

rajat Maheshwari 6rajat Maheshwari 6
Steven

Does my solution helps you to accomplish what you want ?
or not.

please let me know.

Thanks

 
Steven HoughtalenSteven Houghtalen
Hi Rajat,  My appologies for this late response.  Thank you for your response but it did not solve my problem.  I need a query that returns the number of groups.  The query will be used in a Conga report solution, therefore it must stand alone and not being complimented with apex code. Hopefully you or others may have a solution.  Thank you.