Skip to main content

Questions tagged [aggregate]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
37 views

How to use a string function for a report to select only some characters for the group row or column

For a report I want use a string function to only select the two characters of a column: product_group = substr(external_id,4,2). For some reports in the middle substr(external_id,4,2), For others ...
surfmuggle's user avatar
-1 votes
1 answer
56 views

Aggregate results along with respective record names

How to get the MAX(Amount), Min(Amount) from a list of opportunity records with respective Opportunity Names in a single SOQL query. for(AggregateResult agResult : [Select Name, MIN(Amount) 'MinAmount'...
indrasen neelam's user avatar
0 votes
1 answer
69 views

Group By fails with invalid field - How to handle encrypted fields?

I want to find every record that occurs at least two times. The result should be something like this MyLineItem__c Type__c ItemValueString__c Count Foo Boo Booze 2 Yal Bal Jazz 2 Xul Xal Xray 3 I ...
surfmuggle's user avatar
0 votes
0 answers
325 views

EXCEEDED_ID_LIMIT: Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch error is thrown REST API

We are making REST API call to execute and get SOQL query results from a Salesforce org through batch class which is failing with the error message EXCEEDED_ID_LIMIT: Aggregate query does not support ...
Akshatha S's user avatar
0 votes
0 answers
93 views

Marketing Cloud Ampscript add and group by fields

Looking to add the Cost here and grouped by OrderId and purchaseNumber. I have the below but I think it is incorrect. I have other fields in the Data Extension but want the sum of cost aggregated by ...
Stewie's user avatar
  • 1
0 votes
1 answer
189 views

Field must be grouped or aggregated: Name?

I'm working on a query for an invoice template. We want for the "main" products to be displayed on the same list and the one time fees products to be displayed on an other list. We have ...
Audrey's user avatar
  • 1
0 votes
1 answer
57 views

Merging all the query in 1 query and get the different result in variables and pass that to parent class

I was querying the records in different methods based on different conditions but now I have been asked to merge all the queries in one query for efficiency purpose and use of wrapper class. I was ...
SF Learner's user avatar
0 votes
2 answers
508 views

Combining where and having clauses in group by

I am running a group by query. As part of this, I want to check the sum of one field, and then check if that sum exceeds a number. The number itself depends on the value of a second field, which is ...
hamayoun's user avatar
  • 2,777
4 votes
1 answer
321 views

How can I prevent a ContentDocument being deleted when it is linked to a record meeting certain criteria?

I have ContentDocuments being used to capture "proof" against certifications. Once the submitted certification (and "proof") has been reviewed, that certification is marked "...
Phil W's user avatar
  • 37k
-2 votes
1 answer
363 views

Aggregate Queries: Can I return values where GROUP BY size is greater than 1?

If I say SELECT count(id), field_one__c, field_two__c WHERE field_once__c > 1 AND field_two__c < 6 GROUP BY field_one__c, field_two__c could I have it only return groups where the size ...
Help's user avatar
  • 1
0 votes
1 answer
612 views

Aggregate child records with multiple values

I need to find the max date of 2 field on Object__c Structure Object_A is parent Object__B is junction object where Object__A and Object__C are lookup fields Object__c is object that has the date ...
Phuc's user avatar
  • 373
0 votes
2 answers
206 views

how to take single field value when use the ',' in field value in csv file

for(sObject sObj : scope) { AggregateResult ar = (AggregateResult)sObj; Integer IdCount = (Integer)ar.get('cnt'); String accName = (String)ar.get('accName'); ...
sunny roxx's user avatar
2 votes
1 answer
451 views

In Start Method I use Aggregated Query (queries use GROUP By ),then how to check In Execute Method Limit&Number of records we can get using this Query

In Start Method I use Aggregated Query (queries use GROUP By ),then how to check In Execute Method the Aggregate Query how much record Fetch Limit & Number of records we can get using Aggregate ...
sunny roxx's user avatar
0 votes
2 answers
1k views

SOQL to get all records with in a given date range

Below is my sample data: I am trying to form a query where I can get records within a date range. Date Range is start of the week to end of the week. For example I want all records that falls between ...
SfdcBat's user avatar
  • 4,811
0 votes
2 answers
467 views

SOQL Aggregate query for related opportunity

I want to use accounts and related Opportunities in my LWC. @AuraEnabled(Cacheable=true) public static Account[] getAllAccounts(){ return [SELECT Id, ...
Yauheni's user avatar
  • 29
0 votes
1 answer
138 views

Aggregate result not working in soql query

im new to visualforce and i have this problem: I have a sObject with customField1__c, customField2__c, customField3__c. In my main page (with a standard controller and an extension) i want to display ...
MashaMasha's user avatar
1 vote
1 answer
148 views

Combine values from two maps to a third map

The result should display a table of all accounts from a specific user and the aggregateresult of the related opportunities and sales. I create a map (AccList) of all accounts and add the Ids to a ...
Rag21's user avatar
  • 105
0 votes
1 answer
103 views

Bulkify Aggregation Trigger

Is there a way to combine the two aggregates below. public class AccountClass { public static void UpdatePartnerRollup(List<ID> AccID){ // Get Opp Account Map<Id, Account&...
Laura Bejjani's user avatar
0 votes
1 answer
5k views

APEX Aggregate Query - Query to get Sum of Amount of all opportunities of Account when stage is Closed Won

I am having trouble making the query to get Sum of Amount of all opportunities of Account when stage is Closed Won. Please help me out. This is the Query I wrote. Select SUM(AMOUNT) , ID , Name from ...
Rajdeep Baghel's user avatar
0 votes
2 answers
2k views

Null Pointer exception on a Map get()

I'm getting the following error because of this line of code (line 235) in my Before Update Trigger on Site Survey (when I hardcode the sum here, the test passes): Integer sum = Integer.valueOf(aggSum....
Ryan McNeely's user avatar
0 votes
1 answer
334 views

Database.Stateful in Batch gives errors

I have tried an aggregate query, but the result size is too large. So I built a new batch to run over the data and create an aggregation over Account and Product. Condition is that the Revenue/...
Andrea Voggenreiter's user avatar
0 votes
1 answer
299 views

SOQL aggregate functions number fields

Trying to use an aggregate query to count certain records. Now I know that Number type fields cannot be used in Group By so I'm trying the following: SELECT Count(Id), Max(Number_Field__c) FROM ...
AvailableName's user avatar
0 votes
1 answer
77 views

SOLVED: AggregrateResult is not returning Value

I am attempting to calculate the sum MRR of Assets related to an Account and add it to a field on the Opportunity object. The code doesn't show an error but does not return values when new ...
Egypte's user avatar
  • 31
0 votes
1 answer
1k views

What is the maximum number of rows that can be counted by a SOQL count query?

I recollect that: select count() from Contact will now work for more than 50,000 rows (but can't find documentation on that improvement). My question is whether or not there is a new (much higher) ...
Keith C's user avatar
  • 136k
0 votes
1 answer
367 views

marketing cloud - how to join my audience with subscribers having a distinct value [closed]

I have an audience in a table called wtab which contains a column mail, and I want to join it with the subscribers data view without duplicates. when I have one 1 column I can use the DISTINCT keyword ...
eeadev's user avatar
  • 340
6 votes
0 answers
409 views

SOQL Aggregate functions circumventing limits?

We're working in a managed package that leverages SOQL aggregate functions and we want to ensure we are considering governor limits appropriately. To prepare for it we have created a Scratch Org with ...
jonathanwiesel's user avatar
1 vote
2 answers
675 views

LWC for:each needs 3 levels, but SOQL query aggregate relationship limited to 2. What's your best practice?

so I have a structure like: <template for:each={containers.data} for:item='container'> <....> //container info <template for:each={container.Pallets__r} for:item="pallet"&...
Dextersecret's user avatar
1 vote
1 answer
272 views

SOQL Aggregate query

I am trying to query the most recent ActivityDate on an Account. Since aggregate function does not work on the Standard ActivityDate field on Tasks, I created a custom field ActivityDate__c to return ...
Julian's user avatar
  • 33
1 vote
1 answer
2k views

Counting RecordType records

I am using simple_salesforce in Python3 to send query_all() SOQL queries against the REST API. Now: sf.query_all('SELECT Id FROM RecordType') returns 53 records. But: sf.query_all('SELECT COUNT(Id) ...
Reinhard Seifert's user avatar
3 votes
1 answer
1k views

System.LimitException: Too many query rows: 50001 - How to solve it with a batch?

I need to create a summaries record for each result generated by the following query, which returns around 12K. The trouble is the aggregate result has to query 600K records, so I get 'System....
wmin's user avatar
  • 69
2 votes
2 answers
5k 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 ...
user569925's user avatar
  • 1,179
0 votes
0 answers
31 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 ...
peXeq's user avatar
  • 471
0 votes
0 answers
206 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 '...
peXeq's user avatar
  • 471
1 vote
1 answer
527 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 ...
rexxar2's user avatar
  • 11
0 votes
1 answer
694 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 ...
Hans Donkersloot's user avatar
1 vote
1 answer
582 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. ...
Josh's user avatar
  • 440
1 vote
1 answer
3k 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 ...
BoDiE2003's user avatar
  • 467
0 votes
1 answer
1k 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 ...
user3636636's user avatar
3 votes
1 answer
341 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 ...
Mike Jones's user avatar
0 votes
1 answer
520 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 ...
Hennry's user avatar
  • 35
0 votes
1 answer
655 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 ...
Robs's user avatar
  • 9,396
-2 votes
1 answer
1k 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');
raja's user avatar
  • 1
4 votes
1 answer
397 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()? ...
Semmel's user avatar
  • 2,509
0 votes
1 answer
78 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) ...
peXeq's user avatar
  • 471
0 votes
1 answer
1k 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 ...
manymanymore's user avatar
6 votes
1 answer
666 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 ...
Robs's user avatar
  • 9,396
3 votes
0 answers
633 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 ...
zashu's user avatar
  • 143
0 votes
2 answers
272 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 ...
adming32442's user avatar
2 votes
1 answer
104 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 ...
TCassa's user avatar
  • 878
0 votes
1 answer
113 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 ...
Matt M's user avatar
  • 1,477