+ Start a Discussion
Venkata Sravan Kumar BandariVenkata Sravan Kumar Bandari 

I can't understand why it is throwing error for this statement

Database.getQueryLocator('select id, name, email, birthdate from contact where calendar_Month(birthdate) =: System.today().month() AND day_In_Month(birthdate) =: SYstem.today().day()');

i have tried in many ways from anonymus also but its not working
ERROR: System.QueryException: unexpected token: '('
Best Answer chosen by Venkata Sravan Kumar Bandari
Venkata Sravan Kumar BandariVenkata Sravan Kumar Bandari
Thank u to both of you for replying me
Those statements also not working
i changed like this and it is working.
 
Integer m = System.today().month();
        Integer d = System.today().day();
        return Database.getQueryLocator('select id, name, email, birthdate from contact where calendar_Month(birthdate) =: m AND day_In_Month(birthdate) =: d');

 

All Answers

BalajiRanganathanBalajiRanganathan
use this
Database.getQueryLocator('select id, name, email, birthdate from contact where calendar_Month(birthdate) = ' + System.today().month() + ' AND day_In_Month(birthdate) = ' + SYstem.today().day());

only simple bind variables are allowed in dynamic SOQL.

Look at the considerations
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_soql.htm
Himanshu ParasharHimanshu Parashar
Hi Venkata,

You ar mergning two different syntax with each other when you are generating dynamic query you can't use : operator. Please find the correct version below
 
Database.getQueryLocator('select id, name, email, birthdate from contact where calendar_Month(birthdate)=' +
System.today().month() + 'AND ' + 'day_In_Month(birthdate)='+ SYstem.today().day());

Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S.  If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Venkata Sravan Kumar BandariVenkata Sravan Kumar Bandari
Thank u to both of you for replying me
Those statements also not working
i changed like this and it is working.
 
Integer m = System.today().month();
        Integer d = System.today().day();
        return Database.getQueryLocator('select id, name, email, birthdate from contact where calendar_Month(birthdate) =: m AND day_In_Month(birthdate) =: d');

 
This was selected as the best answer