Questions tagged [aggregate]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4
votes
1answer
8k views

How to use ORDER BY and GROUP BY together in the same query

I am trying to retrieve a list of LoginHistory for a bunch of users, but only want the most recent LoginHistory for each user. I have been trying this query, but I keep getting an unknown parsing ...
0
votes
2answers
60 views

Aggregate query with filter in batch

I would like to use aggregate query in batch job but I'm running into an error: HAVING expression must be grouped or aggregated Would also like to understand how can I use count from the query ...
0
votes
0answers
14 views

How to get covered my aggregate result in my test class [duplicate]

I have one class and in my test class i am getting only 65 % code coverage, and all my aggregate function is red. How could I cover these lines of code? Here is my class global class ...
0
votes
0answers
8 views

Aggregate Cumulative

It is possible to cumulate the aggregate results? My code below works fine so far, I get for each month a sum of BWS but now I need the cumulative value. For example: January BWS - 100 February ...
0
votes
0answers
21 views

Put Aggregateresult in Chart

I want to count the number of consultingdays each month from the current year. And I want add this values into a line chart. But it doesn't work. If I run the visualforce page I get the error field '...
1
vote
1answer
31 views

SOQL Get child with most rows grouped by parent

Let's say i have the following structure Object Car is a parent of many (object) Incidents that are also children of an Area So the table of incidents looks like this INCIDENTS ID CAR AREA ...
0
votes
1answer
24 views

Can you include only top 10 records in SOQL group?

I have the following Query [Select Supplier__c, Avg(Total_Sales__c) from Submittal group by Supplier__c order by Purchase_Date__c DESC] The issue is that I only want to include the latest 10 records ...
1
vote
1answer
49 views

How to get all account IDs with only one opportunity which is in 'New Opportunity' stage using SOQL query?

I attempted using this query, however this gets all accounts that have one related opportunity in the 'New Opportunity' stage, but the account may have more related opportunities in any other stage. ...
1
vote
1answer
97 views

SOQL: Aggregate, Grouping By and WHERE Clauses not working

This query SELECT Reason, COUNT(Id) FROM Case WHERE RecordType.DeveloperName = 'Problem' AND AccountId = 'xxxx' AND GROUP BY Reason is giving me Unknown parsing error: But when I run the ...
1
vote
2answers
3k views

SOQL - Where iD not in aggregate list

I can't quite get the syntax right on this. I need the query under getAllBadges, last public of code, to exclude any badges found in the aggregate function. However I can't figure out the name of ...
0
votes
1answer
191 views

Updating parent record via Batch Apex

I am developing a batch Apex process to assign an 'engagement score' to Account based on event/ campaign attendance. We use Campaigns to track events and event guests. What I would like this batch ...
3
votes
1answer
56 views

Aggregate Query issue using Tooling API / Partner/SOAP API with C#

I wrote a utility that cycles through a bunch of orgs and pulls out information. I'm using the Partner SOAP API and C# to do this. Now, I'm trying to get some additional information that is only ...
0
votes
1answer
23 views

Want to fetch field from AggregateQuery

I created a Custom Settings and add some records in it. On the basis of that value i write an aggregate query and i want to store that field value in String. // List to fetch all records from ...
0
votes
1answer
73 views

Is it possible to output an aggregate query to a Map<Id, List<Contact>>

Is it possible to output an aggregate query like this: Map<Id, List<Contact>> accountContactsMap = [SELECT aggregate query ...]; Where the Map key is the AccountId and the Map value is a ...
-2
votes
1answer
126 views

Write an aggregate query to return the sum of Closed Won opportunities for the current year (Close Date = THIS YEAR) grouped by the account [closed]

AggregateResult[] groupedResults = [SELECT AVG(Amount)aver FROM Opportunity]; Object avgAmount = groupedResults[0].get('aver');
3
votes
1answer
112 views

Select aggregate into Integer using Database.query()

So we all know we can put an aggregate directly into an Integer, like this: Integer countAccounts = [SELECT COUNT() FROM Account]; Is it possible to do the same thing, using Database.query()? ...
0
votes
1answer
26 views

Aggregate result

The aggregate for the field amount and JZ doesnt work. CLASS Public Class VTP2_class { Public Summary[] Summaries {get; set;} Public VTP2_class() { AggregateResult[] results = [SELECT COUNT(Id) ...
11
votes
4answers
12k views

SOQL aggregate query limit [Updated for Summer18]

I'm trying to use aggregate queries to save work and script statements. The object has a field for each month representing energy usage for that month for a building. In situations where a building ...
0
votes
1answer
192 views

Count the number of details in master-detail relationship

How can I count the number of details in master-detail relationship? Let us suppose I have Detail_Type__c and Master_Type__c. Now if I have and Id of a Master_Type__c record I can do the following ...
6
votes
1answer
345 views

SOQL AggregateResult Query throws error: System.ListException: Row with null Id at index: 0

Background I have this Apex SOQL query: myMap = new Map<Id, AggregateResult>([SELECT OpportunityLineItemId, MIN(ScheduleDate) Starts ...
2
votes
0answers
58 views

Is applying a LIMIT to a Count() query an optimization?

Salesforce has recently updated the way that the Apex Governor counts Count() query row limits so that the entire aggregate is a single SOQL Row (as opposed to previously where each aggregated row was ...
0
votes
2answers
51 views

Combining SOQL Queries

I need to pull out a query that fetches: From My Team object and Package object. Package is a child of Teams From teams I need to pull how many packages is currently in teams and how much each ...
2
votes
1answer
46 views

Finding MIN(1) date in a data extension - error message about aggregate functions

I'm currently trying to find a list of email Addresses with a particular date in a data extension. The data extension can contain multiple instances of the same email address, but with different dates ...
0
votes
0answers
390 views

Currency Conversion Issue

I am working on a OptyLineItem trigger that does a rollup summary on the Opty header of a custom currency field on the OptyLineItem. The default currency is USD and Advanced Multi-currency is enabled....
0
votes
1answer
61 views

SQOL - MAX condition in left inner join

I am getting a syntax error but can't quite figure out what I have mistyped. Can anyone spot what I am missing? Select ID,Name FROM Employees__c WHERE Account__r.Tag__c INCLUDES ('Inactive') AND ID ...
1
vote
1answer
416 views

SOQL aggregate functions do not work with Task.ActivityDate

When I try the following in the Query Editor of the Developer Console: SELECT WhoID, COUNT(Id), MIN(ActivityDate), MAX(ActivityDate) FROM Task GROUP BY WhoID LIMIT 1000 I get the following error: ...
0
votes
1answer
35 views

Errors with AggregateResult

I am getting an error on line 20 invalid character in identifier: Inspection__Service__c. public with sharing class AddedServicesGrouping { public Inspection_Service__c[] Summaries {get; set;} ...
0
votes
2answers
41 views

Manual Rollup (Sum) behaving differently than Reports and AggregateResult Sum

I'm not sure what is going on here. I'm wrote/summed up some anonymous apex to demonstrate some the discrepancies I'm seeing. Sometimes the values are accurate, sometimes close, sometimes just way off....
0
votes
1answer
283 views

Collect text fields in Aggregate Result Query

I have an aggregate result to process OpportunityLineItems by custom field PackageId - using min, max, avg etc for most fields works fine. However, for a text field I want to collect all the values ...
0
votes
1answer
238 views

Get count of records from a child object which has a reference field to a parent object

To put this simply. I have 2 Objects Let's call them SalesRep and Clients. And the relation is a one-to-many relationship (ie: SalesRep(Parent) -> Clients(Child)) So obviously in Clients Object, ...
1
vote
0answers
45 views

Aggregate query on After Insert returns null

I am working on a class that will identify if an account has a primary contact when an contact is inserted or updated.trigger is on contact to fire on after update/After insert. private void ...
1
vote
1answer
28 views

Max aggrigate query has huge cost against # query rows returned limit

So I have a query: AggregateResult[] results = [select max(Cash_Rewards_Number_Field__c) MaxName from Team__c]; This started causing 50001 too many rows returned errors in my trigger. When checking ...
4
votes
1answer
752 views

SOQL SUM() function not calculating the correct value

I have a SOQL query that I'm trying to use the SUM function with. My issue is that the SUM function gives me a totally different result than if i just query the rows and add up the amounts Query 1 - ...
0
votes
1answer
411 views

How to aggregate Quote Line data in Steelbrick?

I'm trying to determine how to best aggregate data up to the Quote object in Steelbrick CPQ when Quote Lines are added or edited. Essentially creating rolled up sums of prices for different fields. ...
2
votes
2answers
655 views

What is more effecient , using SOQL AVG() or to query all records and calculate their average

Is it efficient to calculate AVG using aggregate function, using a group by clause. Like: (Select Designation__c,AVG(Salary) from Employee__c GROUP BY Designation__c) Or is it efficient to fetch all ...
2
votes
1answer
1k views

get MIN date with Id from aggregate result query

the below query works but it does'nt what I'm expecting and the problem with the below query is that it gives me all the record where as; what I want is to get the minimum dob with Id. here is my ...
2
votes
1answer
49 views

Compile error - Return value must be of type : List

I have the above error from this controller, I have very similar one but it doesn't give any compile error. the constructor and the controller is below public class ...
0
votes
1answer
431 views

How to get recently created child object in one soql

I have 2 objects, Portfolio__c and batch__c. We can create batches against portfolio (i.e) batch__c has a lookup field to Portfolio__c. I have a VF page which was showing a list of portfolios and the ...
0
votes
2answers
375 views

Trigger to populate aggregate results from child object to another child object

I want to populate aggregate results in Funding_Cycles_TA__c Which is a child object of Training_Agreement__c. The trigger is on Training_Plan__c which is another child object of Training_Agreement__c....
3
votes
2answers
434 views

Inconsistency with error “Aggregate query has too many rows for direct assignment”

I have a Box__c record with 100 Doors__r, 104 Motors__r, and 0 Wheels__r. ISSUE #1 I am getting the error System.QueryException: Aggregate query has too many rows for direct assignment, use FOR ...
2
votes
2answers
2k views

Issue processing data from aggregate result query

I have a master-detail relation ship where I am updating the parent (lets call it Parent__c) based on its child records aggregated values (lets call the child, Child__c). The child has a relationship ...
1
vote
1answer
298 views

Aggregate query in trigger

I am using the following query in beforeUpdate and after insert: SELECT OwnerId ownerIdVal, Count(Id) oppCount FROM Opportunity WHERE OwnerId IN: ownerIdSet AND lastmodifieddate > 2016-01-...
1
vote
2answers
2k views

Why I can't get the ID from group by along with Count(ID)?

My goal is to get the ID and the COUNT(ID) [ie.expr0]. ? But i am struggling here! Any other way SELECT COUNT(Id),Id, Application_Prefix__c FROM Test__c GROUP BY Application_Prefix__c //ERROR Id ...
1
vote
0answers
85 views

using aggregate query to iterate on vf page

I have the following code: for(table1__c t1 :[Select id,form__c,type__c from table1__c where formation__c=:set_formation limit 10000]){ //create a map of form,list table1 if(map_table1_form....
1
vote
1answer
1k views

how to do sum in soql?

Double sumOfPrice = 0; for(AggregateResult ar : [Select Id,Name, SUM(ProductPrice__c) totalUnitPrice from Inventory__c where OppLineItemId__c = ...
1
vote
1answer
159 views

Incompatible key type object for Map<id,account>

I am trying to write apex code (and I'm learning how) to roll up data from the on the Account from an object with a lookup relationship to the object. Fields from Account: ID, DealCount__c Fields ...
0
votes
1answer
801 views

Display row-wise data into columns in Lightning component

I have requirement to display data in the following format in lightning account page: |Year | Jan | Feb | ... | Dec | |2016 | 100 | 120 | ... | 250 | |2017 | 190 | 0 | ... | 0 | [No data ...
3
votes
1answer
921 views

Querying distinct logins using LoginHistory and COUNT_DISTINCT

I seem to have run in to a SOQL error that I'm hoping someone has solved before. I am creating a dashboard for UserLogins using the LoginHistory object The query I am trying to run is: SELECT ...
0
votes
2answers
171 views

Why is my aggregate query returning no rows when called during test?

I have the following query inside an @HttpGet REST API method: SELECT Document_Id__c FROM Content_Link__c GROUP BY Document_Id__c HAVING Count(Account__c) > 0 When run regularly I see the ...
6
votes
2answers
227 views

how to add lastmodifieddate in aggregate list

AggregateResult[] groupedResults; if(Schema.Account.getSObjectType().getDescribe().isAccessible()) groupedResults = [SELECT Name, FROM Account where Name like :sql or name IN:sql1 Group By Name ...