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
JKinseyJKinsey 

Date Range Help - Controller Extension

I am attempting to produce a custom VFpage that lists only opportunities within the next year.  I'm building an extension to return list views but within my filter criteria.

My issue lies with "And inputdate__c < ??? Today + 365", as seen below from the extension.

I'd rather not create a custom field for Now()+365....

 

 

public List<Opportunity> getOpptySum() {
        return [select name,closedate,account_id__c,inputdate__c,stagename,isclosed
         from Opportunity WHERE account_id__c = :ApexPages.currentPage().getParameters().get('id') 
                             AND isclosed <> true
                             AND inputdate__c < ??? TODAY + 365 Days
                             ORDER BY inputdate__c ASC 
                             LIMIT 50 ]; 
        }

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
AmitSahuAmitSahu

Is this not working  as below ?

 

public List<Opportunity> getOpptySum() {

Date onlyDate = Date.today();
        return [select name,closedate,account_id__c,inputdate__c,stagename,isclosed
         from Opportunity WHERE account_id__c = :ApexPages.currentPage().getParameters().get('id') 
                             AND isclosed <> true
                             AND inputdate__c > onlyDate.addDays(-365)
                             ORDER BY inputdate__c ASC 
                             LIMIT 50 ]; 

 

All Answers

AmitSahuAmitSahu

Is this not working  as below ?

 

public List<Opportunity> getOpptySum() {

Date onlyDate = Date.today();
        return [select name,closedate,account_id__c,inputdate__c,stagename,isclosed
         from Opportunity WHERE account_id__c = :ApexPages.currentPage().getParameters().get('id') 
                             AND isclosed <> true
                             AND inputdate__c > onlyDate.addDays(-365)
                             ORDER BY inputdate__c ASC 
                             LIMIT 50 ]; 

 

This was selected as the best answer
JKinseyJKinsey

I received

Compile Error: unexpected token: 'onlyDate.addDays'

 

So I added : before onlydate.addDays

so...

:onlydate.addDays

worked great!  Thanks!

 

Can anybody tell me what the proper terminology for ":" is?  Why is it needed and what does it do?

 

 

AmitSahuAmitSahu

Sorry I missed that ":".

 

":" is used to specify if we are using a variable in the SOQL .