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
krishnagkrishnag 

soql error

hi i was just practicing SOQL queries and i wrote a test query in apex explorer

 

 

Select Id, Name, Industry,Company_Relationship__c From Account where Company_Relationship__c='Employee' and Lead_Created_Date__c=System.today()

 

 

and when i tried to execute i am getting an error can anyone tell me where my error is.

 

error: unexpected token 'system.today()'

Best Answer chosen by Admin (Salesforce Developers) 
sornasorna

I dont think that system.today will work in apex explorer...jus try with today or today() and try changing the uppercase to lowercase and vice versa...

All Answers

Jeremy.NottinghJeremy.Nottingh

System.today() is acting as a variable in your query, so put a colon (:) in front of it:

 

 

Select Id, Name, Industry,Company_Relationship__c From Account where Company_Relationship__c='Employee' and Lead_Created_Date__c = :System.today()

 

Jeremy

 

krishnagkrishnag

i tried putting a column before i am getting error

 

error:  unexpected token':' [Bind variables can only be used in Apex code]

Jeremy.NottinghJeremy.Nottingh

Sorry, I didn't see you were using Apex Explorer. Instead of using a variable, use a literal of the form 2010-08-04.

 

Jeremy

krishnagkrishnag

nope i tried that too athe beginning itself same error unexpected token.

 

i tried writing

 

date=8/4/2010 1:05 PM

 

 

unexpected error  '/'

Jeremy.NottinghJeremy.Nottingh

If your filter field is a "date" field type, then using 2010-08-04 with no quotes should work. If it is a "date/time" field, then you might use something of the format 2010-08-04T00:00:00.000Z with no quotes.

 

What error messages are you getting, and why do you need to do this query in Apex Explorer specifically?

 

Jeremy

krishnagkrishnag

its not working either way. 

 

the error message i am getting is 

 

unexpected token: '-'   ( pointing to the filed name)

 

the reason why i am writing is just i want to know how many records i have with specific details.

Jeremy.NottinghJeremy.Nottingh

I would recommend you set up a custom Report in the Salesforce GUI, in that case. You can get record counts from there, and it's a lot easier to configure filters and sorting.

 

Jeremy

krishnagkrishnag

my actual case is that only i want to create a report in VF page for which i am using google visualizations. In google visualization we need to pass a query to url to populate the data.

 

so i was trying to execute query and know its working or not

sornasorna

I dont think that system.today will work in apex explorer...jus try with today or today() and try changing the uppercase to lowercase and vice versa...

This was selected as the best answer
krishnagkrishnag

great it worked using just ' today' parameter.But can u help me if i want to find particular month like june.

krishnagkrishnag

i mean like date= particular date and month

sornasorna

I dont think that such functionality is available. because, in SOQL query for the WHERE clause, for ex: you can give "Where createddate =:someDate" and you cannot embed any date functions to the createdDate field in the query.

But if you want to find some records that are created in the month of june, then write the WHERE clause like this: "Where createdDate >= 2010-07-01 and createdDate <=2010-07-31".

 

 

Regards,

Sorna

krishnagkrishnag

its not working when i hardcode the date in the command,

jujubajujuba

Hi 

 

You cannot pass the Date to the CreatedDate field as it is a Date Time field. Please try this

List<Opportunity> opp = [select name from opportunity where createddate > 2010-10-12t00:00:00z];

 

If you are aware of exact datetime value you can go with createddate = that exact date value.

 

I think it will help you.

Thanks