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
Vijaya Kumar RegantiVijaya Kumar Reganti 

SOQL Query Help

Hi Friends,

 

I am trying to do the following query but I am not able to save it and I am getting an error like System.Today() Is not available.

 

Stats__c[] Stats = [Select Id,Mode_of_Travel__c,School__c FROM Stats__c Where CreatedDate = System.Today() ];

 

Please help me to figure out the problem here.

 

Best Answer chosen by Admin (Salesforce Developers) 
Vijaya Kumar RegantiVijaya Kumar Reganti

Hi Friends, 

 

Finally  I got my own Soution as follows.

 

Stats__c[] Stats = [Select Id,Mode_of_Travel__c,School__c FROM Stats__c WHERE CreatedDate = Today];

 

It worked.

All Answers

asish1989asish1989

This query is perfectly fine, There is no relation between System.Today() and query.

You must have written some where else due to that line error is comming.kindly check your code.

Vijaya Kumar RegantiVijaya Kumar Reganti

Sorry the following is the query.

 

Stats__c[] Stats = [Select Id,Mode_of_Travel__c,School__c FROM Stats__c Where CreatedDate = System.Today() ];

 

Please help me to figure out the problem here.

 

 
force noviceforce novice

Change you query like this, It will work.

 

Stats__c[] Stats = [Select Id,Mode_of_Travel__c,School__c FROM Stats__c Where CreatedDate = Today ];

hitesh90hitesh90

Hi vijay,

 

you forgot to put ":" in your query. try to use following query.

 

SOQL Query:

Stats__c[] Stats = [Select Id,Mode_of_Travel__c,School__c FROM Stats__c Where CreatedDate =: System.Today()];

 

Vijaya Kumar RegantiVijaya Kumar Reganti

Hi Friends, 

 

Finally  I got my own Soution as follows.

 

Stats__c[] Stats = [Select Id,Mode_of_Travel__c,School__c FROM Stats__c WHERE CreatedDate = Today];

 

It worked.

This was selected as the best answer