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
bozotheclownbozotheclown 

Odd Date Behavior

Hello.  I am running into an error after tweaking a previously-working AggregateResult line of code.  Does anyone have any guidance as to what is the best way to proceeed.

 

In the below code, I am trying to limit my query to the past seven days (note 'system.today()-7').   Unfortunately, I am receiving errors for the "ClosingDate__c = QueryDate" section of the AggregateResult line.  I have tried to insert brackets, single quotes, etc...and receive some sort of error message each time.  Can anyone provide some guidance?

 

Thanks in advance.

 

public Date QueryDate { get; set;}


QueryDate = (system.today() - 7);

AggregateResult[] ar = [SELECT sum(CustomerDollars__c) FROM Customers__c WHERE ClosingDate__c = QueryDate GROUP BY ClosingDate__c ORDER BY sum(CustomerDollars__c) desc LIMIT 1]; 

 

Best Answer chosen by Admin (Salesforce Developers) 
JoyDJoyD

Is it just that it needs the colon?

WHERE ClosingDate__c = :QueryDate

All Answers

JoyDJoyD

Is it just that it needs the colon?

WHERE ClosingDate__c = :QueryDate

This was selected as the best answer
bozotheclownbozotheclown

I totally missed that.  Thanks much.