Skip to main content

Questions tagged [aggregateresult]

The tag has no usage guidance, but it has a tag wiki.

Filter by
Sorted by
Tagged with
2 votes
1 answer
73 views

How to Create a Fake AggregateResult Object for Testing in Salesforce Apex?

I'm currently working on testing some Salesforce Apex code that involves AggregateResult objects. In my test setup, I need to create a mock AggregateResult object with fields rateId and rateId2 set to ...
Cuban coffee's user avatar
  • 1,596
-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
2 answers
66 views

Aggregated result error: Unexpected token 'createddate'

I have the following Aggregated SOQL List<AggregateResult> groupedSpotOnEs = [SELECT my_application__r.numbers__r.Id eSId, status__r.name status, COUNT(Id) recordCount ...
Thomas's user avatar
  • 2,310
0 votes
1 answer
81 views

How to sum the values of an aggregated query

I have a parent object Account with related contacts these related contacts have (several) related statuses i.e. A B C. These are all the statuses a contact has had. On the parent Account I need to ...
Thomas's user avatar
  • 2,310
1 vote
1 answer
130 views

System.LimitException: Too many query rows: 50001 when Using AggregateResult interface in batch class?

I want to aggrgate Average of Quality Score of Account object based on User's Market and I want to those summary details in one of Custom Object. I have written a batch class where I am using Iterator ...
SFDCDJ's user avatar
  • 1,904
-1 votes
1 answer
64 views

Apex Controller to get the total no of Accounts and Opportunities group by Owner Name

I have a requirement to get a table as below, I was creating an apex controller as below, but its showing issues, May i know where i get wrong ? public class AccountController { public <...
Sourav's user avatar
  • 15
1 vote
2 answers
830 views

How to reference field from an AggregateResult Map?

I am receiving an error when trying to reference the field alias CaseCount__c in my map. It says "Variable does not exist: CaseCount__c". How can I reference this field value? List<...
Alan's user avatar
  • 25
0 votes
1 answer
420 views

How to write a SOQL Query in Apex to Fetch the minimum amount of all the related opportunities for an account

I have an account which has related opportunities. For those opportunities I wish to get the minimum amount through a SOQL Query. How can I achieve this if I need to use only 1 SOQL Statement in Apex? ...
Amax1's user avatar
  • 121
1 vote
1 answer
49 views

Aggregated result with multilevel map in apex

I am trying to model aggregated data with the with bellow approach. I am Stuck in shaping up data like as shown bellow so that I can add it into my component. I tried with conditional logics to build ...
Kartik.S's user avatar
0 votes
1 answer
1k views

Batch reachs the limit of 50000 records

I trigger via flow the class below to get the sum of BWS_val__c if the status not contains 'Pol', but if the status contains pol the class execute a batch class. I thought that the batch class can ...
FenTro's user avatar
  • 29
1 vote
1 answer
501 views

SOQL aggregate query issue with number fields

I was trying built aggregate query on number field, Found an strange behaviour. Object Considered: Campaign I have used Visual Code for execute SOQL for my analysis. Use Case 1: NumberOfContacts ->...
NITHESH K's user avatar
  • 2,535
0 votes
2 answers
471 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
139 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
0 votes
1 answer
159 views

How to retrieve only the highest version number and work with those results

I need to retrieve only the highest version number from a table. Then I need to read each rows results. How do I accomplish this using aggregate results? I only want to retrieve the rows in yellow and ...
Ohmicron's user avatar
  • 707
2 votes
1 answer
3k views

Method does not exist or incorrect signature: void valueOf(Object) from the type Decimal

I am getting errors when storing my aggregate result value in the currency field. I have tried to look into a similar error but not getting anything. Below is the logic which I am trying to implement. ...
Avesh's user avatar
  • 137
0 votes
1 answer
53 views

Modify AggregateResult List value to take substring of it for displaying on vfp

**solved: I was able to return them as sObject instead of list since I know I will always receive a single value. I was then able to use right function to take my substring. Below is my controller I ...
Wes's user avatar
  • 41
0 votes
1 answer
78 views

Argument cannot be null when testing controller that displays some dates on a lightning page

Controller: public with sharing class DatesController { public String vehicleId {get;set;} public List<AggregateResult> AggregateResultList{get;set;} public List<...
Wes's user avatar
  • 41
0 votes
1 answer
1k views

How to make Sum of grand child field and show it on Parent record

my requirement is whenever OpportunityLineItem Created makes the sum of quantity available for Opportunity and also take care of rest of Opportunity for particular Account and update Total Sales ...
whoisnilu's user avatar
  • 115
0 votes
0 answers
171 views

Add Number sequence afterwards based on this Group and Order

I need some help with the following. After the collection of different records across Salesfore, a set of new invoice records is created like the example below This list is Grouped by Invoice number ...
Marco P.'s user avatar
0 votes
1 answer
1k views

how to get aggregate result from inner query in trigger

for(bank__c parentSetObj: [Select Id, Name, Count_of_Credit_Cards__c, (Select Id, bank__c,amount__c From credit_card__r ) From bank__c Where Id IN:accSetId]){ as aggregate functions are not allowed ...
user13956399's user avatar
1 vote
1 answer
149 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
3 votes
1 answer
2k views

Merging two lists into one

I have two different lists. A list of opportunities and a list of sales (Umsatz__c), the accountid appears in both lists. How can I merge these lists into one finallist at account level? This list ...
Rag21's user avatar
  • 105
1 vote
0 answers
63 views

Visualforce table for aggregate result grouped by CreatedBy.Name

I'm trying to create a custom report table in Visualforce based on an aggregate result retrieved by the SOQL: SELECT CreatedBy.Name, Description, SUM(Value1), SUM(Value2), SUM(Value3) FROM Object__c ...
Daniele's user avatar
  • 11
3 votes
2 answers
1k views

How do I set some List<Account> fields from a List<AggregateResult>?

I am learning Salesforce and Apex and I got the following task: whenever an opportunity is updated or created, calculate the related accounts total number of opportunities and total sum of those ...
devvvvvvvvvvvvvv's user avatar
0 votes
2 answers
581 views

Display list<aggregateResult> in lightning component

How can I return a List<AggregateResult> to a lightning component and display the individual values in the lightning component. I have a table, and at the bottom of the table I need to display ...
ThatGuy's user avatar
  • 85
0 votes
1 answer
1k views

Dynamic SOQL Query -> Select Sum(Custom Metadata Field) Question

This is my first intro with custom metadata and also dynamic soql. I am trying to set it up so that users can set up certain fields that they would like to use for the apex class calculation via ...
Tom G's user avatar
  • 170
0 votes
1 answer
118 views

Aggregate Queries with too many groupings

I'm curious about the efficiency of an aggregate query with too many groupings. I'm working on a scheduled Apex job that will run daily, and compare two aggregated fields with some fields from a ...
Andrew Favaloro's user avatar
1 vote
1 answer
1k views

Apex Test Class returning Null Value but appears to be working correctly?

My test code is retrieving "Null" instead of 1 when I test the below trigger. However, it's populating appropriately in the Salesforce instance itself. The goal of this trigger is to relate ...
amclane's user avatar
  • 11
0 votes
1 answer
72 views

Issue with Batch Apex Updating Results from AggregateResults SQOL Query

I have an object Referral__C where we add a NHC_Tracker_ID(Nhc_Tracker__C another object). I want to update the fields on NHC tracker by count Referrals and Unique addresses related to Referral. My ...
Niraj Dev's user avatar
0 votes
1 answer
67 views

Web to lead assignment to User with least open lead count

I have created a Map 'userIdWithOpenLeadCountMap' and grouped by OpenLeadCount in the ASC order. Then I am getting the first Key from the Map (UserID:005E0000003X2MH) and assigning a new lead to this ...
GroundToCloud's user avatar
3 votes
2 answers
6k views

What is the benefit of using Aggregate Query in Salesforce

I am wondering if there are any benefits of using Aggregate Query in Salesforce. Lets's say we have 2 code snippets here. Let's say accIdSet is a collection account Id we are working on. CODE 1 : for (...
Noob_NoVoice's user avatar
  • 2,709
0 votes
0 answers
48 views

Group AggregateResult by field on records

I am trying to get the number of zipcodes base on the 'type' field on the record. So if there 2 record where the Type is 'Right' and the postal code is 12345, and a user creates another record where ...
Phuc's user avatar
  • 125
0 votes
2 answers
620 views

SOQL Aggregate expressions

This class is still work in progress, how to resolve the error from Line 8 - 'only root queries support aggregate expressions' does this mean AggregateResult can't access values inside a subquery? ...
Pluto's user avatar
  • 31
0 votes
1 answer
78 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
534 views

getting error "Illegal conversion from List<AggregateResult> to List<Opportunity>" [duplicate]

Here is my code public with sharing class estimatevsPipeline { @AuraEnabled public static List<Opportunity> getestimatevsPipeline() { return [ SELECT SUM(...
Gaurav Kumar Pandey's user avatar
1 vote
1 answer
756 views

Dynamically Finding the column names and values in AggregateResult

I am looking at the Salesforce Documentation for working with SOQL Aggregate Functions and seeing that we need to leverage .get to access the specific column value. Is there a built in method for ...
Matthew Metros's user avatar
4 votes
1 answer
89 views

Apex AggregateResult in Managed Packages

When doing database aggregations in Apex and SOQL, we'd normally do something like this; List<AggregateResult> prodsWithPositiveQuantityRem = [ SELECT Product_Family__c, SUM(...
John Mutuma's user avatar
0 votes
1 answer
287 views

Filter records by Date - SOQL

I am trying to get some duplicate records by using SOQL but i also want an analysis per day. select max(id)maxID,count(id),name, ea_System__c, ea_BusinessLine_Code__c, ea_CustomerId__c, count(Id) ...
Giorgos Galaios's user avatar
0 votes
1 answer
800 views

How to split a dynamic list into batches so that it doesn't exceed Apex CPU Limit?

I have a apex class which uses a many aggregate queries to form a list<Survey__c>. Apex CPU limit is exceeded when I try to insert this list. I have already divided the list into two parts, but ...
Prerana's user avatar
  • 23
1 vote
1 answer
144 views

Apex: How to figure out actual sobject that has been queried having only AggregateResult type

To narrow down the problem - we have a method like this: private static Object doSomeProcessing(List<AggregateResult> records) { ... // need to add additional logic here based on sobject ...
wesaw's user avatar
  • 3,130
0 votes
0 answers
478 views

OpportunityLineItemSchedules grouping by Date in SOQL

I have a list of products with associated schedules where each schedule has different Revenue and ScheduleDate values. I'm trying to get the get the aggregate of Revenue by DATE across the ...
SMorse's user avatar
  • 39
0 votes
1 answer
79 views

Field calculations per Account and their total

I have a object called Business transactions which is related Account(Planner). I need to calculate the total of one field called commissions for each Account and show them in total. I'm able to ...
Nikhil Pandit's user avatar
0 votes
2 answers
40 views

Not able to get max amount and update the status in Apex

i have requirement where i need to get all orders from account and need to check max amount from that order and need to update the status of order to InProgress. then from account1 ==>order4 needs to ...
akash's user avatar
  • 1
2 votes
1 answer
503 views

AggregateResult Number format in Visualforce Page

Hi all I have an aggregateResult query which is pulling correctly into a visualforce page block table. All the numbers are have 0 digits right of decimal but the values display with one 0 to the right....
jaw999's user avatar
  • 1,317
0 votes
1 answer
203 views

How Do I display an aggregateResult list in a visualforce pageBlockTable?

I have a class that is correctly pulling an AggregateResult in from a child object on a custom object. I'd like to use an pex:pageBlockTable to display the aggregateResults but when trying to setup ...
jaw999's user avatar
  • 1,317
0 votes
1 answer
883 views

Handling no results for SOQL AggregateResult Query

Edit: Figured it out, details in the answers. Original Question I have a wire in my JavaScript code to get the results of a SOQL query. It is an aggregate query to get the maximum of a certain field....
Eric Tepper's user avatar
0 votes
1 answer
42 views

My wrapperlist is not showing up

I trying to create a table to provide metrics on the number of Account and Contact records grouped by state. So each state will have two number of count id. Below is a code for my class and visual ...
Hieu Vuong's user avatar
2 votes
1 answer
860 views

How to add an aggregate result from a SOQL query inside a map? Shows error- Unexpected token '['

I am trying to create a map of Opportunity ids and a count of its Opportunity Line Items. Map<Id,Integer> opptyIdLineCount = new Map<Id, Integer>(); AggregateResult[] aggOpptyIdLineCount =...
Rithu's user avatar
  • 23
3 votes
2 answers
1k views

Getting AggregateResult variables from Execute Anonymous Window

I am trying to execute a block of code using the Execute Anonymous Window that is meant to delete some duplicated data, but I am getting this weird error about a variable not existing even though my ...
BlondeSwan's user avatar
  • 1,098
0 votes
1 answer
499 views

Error: BillingAddress does not support aggregate operator COUNT

I am trying to get a list of Accounts that has the same BillingAddress I tried to get an aggregateResult however got the error: Line: 2, Column: 34 HAVING count(BillingAddress)>1 ^ ERROR at ...
GroundToCloud's user avatar