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
Austin GutzAustin Gutz 

Aggregate/Order/Count SOQL Data

I have the following query:
SELECT 
Completed_Date__c, CreatedDate, Description, Subject__c, Account.Name, Account.Status__c,CreatedBy.Name, Owner.Name
FROM Task 
WHERE
Completed_Date__c = LAST_WEEK 
AND
(
Subject__c LIKE '%Customer%' OR
Subject__c LIKE '%Lead%'
)
AND
Owner.Name = 'Employee Name'
This query pulls all tasks associated with Owner.Name = 'Insert Employee Name'. I'm then using the result to populate a Conga Word table that displays the task Subject. The problem is the results look like this:

Customer - Meeting
Customer - Meeting
Customer - Email
Lead - Contact
Lead - Contact
Lead - Contact

I'm trying to find a way to group and count the results. So something like this

Customer - Meeting 2
Customer - Email 1
Lead - Contact 3

Normally I could achieve this using a summary report and pull that information into the Conga template but the users running the merge don't have access to export reports so I have to use queries. 
v varaprasadv varaprasad
Hi Austin ,

I am not sure but plz check once below query  :
 
AggregateResult[] groupedResults = [
SELECT 
Completed_Date__c, CreatedDate, Description, Subject__c, Account.Name, Account.Status__c,CreatedBy.Name, Owner.Name
FROM Task 
WHERE
Completed_Date__c = LAST_WEEK 
AND
(
Subject__c LIKE '%Customer%' OR
Subject__c LIKE '%Lead%'
)
AND
Owner.Name = 'Employee Name'
AND
GROUP BY Subject__c]

Thanks
Varaprasad
Austin GutzAustin Gutz
2 things

1.) I keep getting an error that the query must start with SELECT. Am I doing something wrong?
2.) I have a custom link that is clicked that runs this and a few other queries. My link captures &Id={!$User.Id} - How can I pass that id to Owner.id = in my queries?
I tried
​Owner.is = {!$User.Id}'

but get an error of incorrect id type.

*This is maybe my 3rd-day using SOQL so I apologize if these are stupid questions!