The tag has no usage guidance.

learn more… | top users | synonyms

1
vote
2answers
25 views

Aggregate SOQL cannot get average

So I've read the following: Can I assign Aggregate SOQL Result directly to variable? Using AggregateResult in Salesforce.com SOQL Soql avg,sum,max error in apex program Working with SOQL Aggregate ...
0
votes
0answers
24 views

Pulling max value from multiple custom objects onto account field based on inputted date

My org records our monthly purchases on a custom object 'Factor Data'. Each month's information is displayed on the master account's page just like "Opportunities", "Contacts", "Activity History", etc....
1
vote
1answer
32 views

convert aggregate result to list

I'm passing a list to a serialize JSON string value back to a Visualforce page. Traditionally I can easily pass back a List to the JSON. However, my SOQL is an aggregate. I need to be able to ...
0
votes
0answers
60 views

Getting Id of object in the Aggregate query

I am trying to get Aggregateresult which also returns the Id of the object being queried. i.e. Map<Id,AggregateResult> result = new Map<Id, AggregateResult>( [SELECT Count(Id) cnt,...
1
vote
2answers
96 views

How can I aggregate a Boolean value for a column in SOQL?

I have a custom object customobj__c with the following fields: contact__c (lookup), responded__c (boolean), click_count__c (integer) ... I can aggregate the click_count using: SELECT contact__c, ...
4
votes
3answers
80 views

Aggregate Values with Limits and Orders

Basically, what I am looking to accoplish with the SOQL Query, is to return the average value of the Last N (20) SAT scores from the Case object. The query would essentially look like this: Select ...
3
votes
1answer
97 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
100 views

Incompatible types since an instance of List is never an instance of AggregateResult

I am trying to execute following apex class , But facing the following error Incompatible types since an instance of List is never an instance of AggregateResult. I am using the below code: public ...
6
votes
1answer
61 views

Batch Apex - Need help

This is my first time trying to use batch apex. I copied the example from Trailhead and attempted to move my class code into it. I don't think I have the aggregate query coded correctly but I don't ...
0
votes
1answer
25 views

Aggregate List displaying Repeating values

All Apex experts! I am correctly displaying an Aggregate Result set from 3 distinct Salesforce Objects. However I am seeing an issue with repeating values on my Visualforce component with these 2 ...
0
votes
1answer
20 views

Apex AggregateResult from 2 Objects

Calling all the apex gurus! I have a class that is working as expected with 1 Object and 1 Aggregate Result query. I have a requirement to Aggregate a second Object and include that in my result ...
0
votes
0answers
34 views

Retrieving All Duplicates With SOQL, And Loop Through Each Set Of Duplicates

I have two tables: Suite__c and Lease__c. Multiple leases can be pointing to the same Suite. This is problematic if these multiple leases have the 'Comparable' flag set to true. I am attempting to ...
2
votes
1answer
47 views

AggregateResult Use Case Best Practice

Trying to determine best scenarios for using AggregateResult e.g. Versus using a for loop gathering totals with += or similar syntax.
2
votes
1answer
36 views

split before GROUP BY soql

I have a field which has the values in the format [5 digits-3 digits] 12345-123 34646-345 12345-133 I want to Group BY this field with the just the 5 digit number only (not the ...
2
votes
1answer
51 views

Find the max owner for a given record

Schema I have a scenario where two records are related via Lookup. A -> B(has Lookup[A]) So parent A can have many related children B objects. Since A and B are related through lookup and ...
1
vote
2answers
94 views

How to check check earliest date & latest date in apex class

I have an object X__c which has 2 date fields D1__c & D2__c. There are meny records for this object X__c. I want to get from all records the earliest date value from D1__c field and latest date ...
0
votes
1answer
21 views

Extract aggregratelist value where conditions are met

I need some continued help with this project. I have my aggregrateResult list with the needed data for every account. How do I pull the data just for the current account? global class ...
0
votes
0answers
24 views

Update Object with unique values from Child object using Aggregate result

I am trying to update a field on the Quote (Operational_Start_Date__c) from the results of an aggregate result query. The trigger runs on quote, queries QuoteLine for unique values and update the ...
0
votes
2answers
104 views

Illegal assignment from object to string Aggregate Result

I am getting an "Illegal assignment from object to string" on an Aggregate Result trigger. Here is the code snipped; List<AggregateResult> uniqueCountries = ([SELECT ...
0
votes
1answer
20 views

Multiple query aggregateResult

I am trying to find my way to wrap my head around this problem. I am trying to eliminate 3 of these for AggregateResult loops and just make one since it is getting the same object. I am a new ...
1
vote
1answer
39 views

SOQL query aggregation

I need to provide statistics to the users in my VF Page, showing the total of records they own where the status is New, In progress, Approved, Pending, Converted I have tried the below query in my ...
1
vote
2answers
106 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 ...
1
vote
2answers
42 views

How to sort when we use aggregate function?

I have a formula field that orders a particular field values. Example: A field for employees profession, for each profession there is an equivalent number value like, "IT = 1, Doctor = 2". I'm using ...
0
votes
1answer
37 views

soql aggregate query has issue returning id of record

i want to query the opportunities for a using a set of account ids and get the opportunity for each account that has the most recent start_date__c. so im grouping the opportunity query on account and ...
1
vote
1answer
34 views

Why does SalesForce aggregate query discards two last digits?

I have created a simple object called Object__c. Also Number field (18,0) I have created for this object called Number__c. Then I have created one record with name 'x' and Number__c value of '111 111 ...
4
votes
1answer
88 views

Apex aggregrateresult error

Any help why I'm unable to add this? List<AggregateResult> revenue = [select SUM(Daily__c) rev, Client__r.Name from Commissions__c]; Integer totalMonthlyRevenue = 0; for ( AggregateResult i :...
0
votes
1answer
58 views

Working off the Quote in Visualforce, how can I access Contacts? Getting an unsupported complex expression error

The quote is associated with an account, and the account has contacts. I can access the account data just fine, but when I try to display any contact data then it fails with the following error: ...
0
votes
0answers
34 views

Join two aggregate results with mutually exclusive records

I have below two AggregateResult where I need all the records that come in query results whether Rep_abv__c (of Compliance_Incidents_abv__c) and Id (of User) matching or not so that I can keep all ...
1
vote
1answer
124 views

Find AggregateResult Fields Dynamically

I ran across some code a while back to find fields within an AggregateResult dynamically to do some processing irregardless of what was in it. AggregateResult results = [SELECT COUNT_DISTINCT(...
1
vote
1answer
42 views

Can an aggregate function be in SOQL where clause?

Can an aggregate function be in SOQL where clause? Looks like it cannot but I can't find anywhere a documentation a clear answer if it is forbidden and why if it is
12
votes
1answer
220 views

Aggregate SOQL - How Many Fields Can Be Grouped?

As stated in the title, is there any maximum on the number of fields that can be passed into a GROUP BY clause? I can't find any documentation on it. For example, if I had the following query: SELECT ...
0
votes
1answer
129 views

Aggregate Query Returns Results in Dev Console but not Apex

I have an Apex Class that retrieves an aggregate result of Contacts per Accounts in order to validate a maximum of 2 Contacts of a certain type. I have tried several things. First I used a set and ...
5
votes
2answers
155 views

SOQL Query of lookup relationship

I have an SObject called Team_Member__c It has a lookup field Manager__c pointing to Team_Member__c, so the Team_Member__c SObject is related to itself. The relationship represents a management ...
0
votes
1answer
78 views

aggregate soql select contact fields from opportunity query

wondering if anyone can help me with a query on opportunity that contains contact fields. i've tried a bunch of solutions but no luck yet. Select count(Id), Account.Contact.SomeField from ...
0
votes
1answer
208 views

SOQL query date condition?

I need a where clause on task..where its calculates the count of tasks every week between Friday and Thursday.. I know it will be a Aggregate query.I am confused how to calculate every-week..What ...
4
votes
2answers
1k views

Display an aggregate result on a visualforce page

I try to display on my visualforce page the result of a soql query (an aggregate result precisely). Here is my controller (a partof it) : public List<AggregateResult> somme {get; set;} public ...
2
votes
1answer
152 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
0answers
38 views

Opportunity analyze

I need an analyze of our opportunities for each team in our org. First I select the team and then should the visual page show a table of all accountOwner of this team and the different recordtypes (...
0
votes
1answer
234 views

Counting query results and displaying them in visualforce

I'm trying to count the number of each asset for an account and I'm not sure where I'm going wrong. I'm getting this error "Content cannot be displayed: Invalid field quantity for AggregateResult". ...
3
votes
1answer
132 views

For loop run just once

I have seven different recordtypes, but it seems that the first "for" (FOR (RecordType RType : RTypeList) loop run just once. The debug log show that the sql find 7 rows. 09:22:47.089 (89771210)|...
2
votes
1answer
524 views

Put AggregateResult in Map

I'm trying to put my AggregateResult in a map so that I can reference it later in my code. trigger NoOfLiveProducts on Account (after insert, after Delete, after update) { map<Id,Integer> ...
1
vote
1answer
786 views

Convert aggregate result to decimal

I need to fetch the AggregateResult 'sett' for each Opportunity in a loop, from a map and convert them into decimals. I've seen Ariel's solution on this post but when I use it, it causes an error ...
2
votes
1answer
347 views

SOQL Aggregate calculation error due to multi-currency

I'm trying to calculate the SUM of all values in my Target__c field, on my Target__c custom object. When the below code is executed, my debug log shows that updatedTargets contains the correct target ...
1
vote
1answer
492 views

Help displaying aggregate results in footer of pageblock table

I am trying to create a Visualforce page to display a list of related records (lookup relationship) in a PageBlockTable. I would like to include a footer row that displays the sum of one of the ...
4
votes
2answers
371 views

What is the coalesce() eqivalent?

Much like this post here: SOQL: Avoid count with NULL results return 0 (zero) instead I have an instance where I am using aggregate functions like COUNT() and MAX() on a collection of Opportunities. ...
2
votes
2answers
536 views

SObject Exception: Invalid field for Opportunity

I am attempting to set a flag on the Opportunity Header based on an Aggregate Query of the Opportunity Line Item object, and I keep getting an SObject Exception. My code and the error log are below, ...
1
vote
2answers
332 views

Apex Trigger to Sum field using button

I have 2 custom object(Master Contract and Contact Person), i have lookup relationship between them. I have related list Contact Person in Master Contract Object with button named Recalculation. In ...
1
vote
1answer
362 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 = ...
2
votes
2answers
47 views

Grouped Query Call

I'd like to display a short table of Users and their Activities. I can get to the id but when trying to display the username I run into grouping issues or relationship issues. Here's my class: public ...
4
votes
3answers
117 views

SOQL: Returning results where detail (M-D) count is at least 5

I'm trying to set up a query that will return which contacts have over 5 deals with us. We have a custom sObject which is (terribly) named, contacts_deals__c which serves as an intermediary table ...