You need to sign in to do that
Don't have an account?
raj123
Date in the query string is not populating correctly , instead string is populated
Hi Folks
I have an issue
date d = system.today().addDays(-2);
String strQuery='Select Id,Collection_Center_Code__c,RMA_Number__c,Case.Contact.Name,Contact.Email,SC_Received_Num_Boxes_WDE__c,SCReceivedPalleteID_WDE__c,SCReceivedTracking_WDE__c, SCReceivedTime_WDE__c,SCShipToWDDate_WDE__c,(Select Id,Received_Date__c From Order_Status__r where received_date__c > :d and received_date__c = null ) From Case t Where Collection_Center_Code__c =\''+Code+'\'';
the date variable is coming as d instead of value when i check in debug logs
can some one help me with this
thanks,
You might have to convert the the value in d to string, and it will work because the query string expects a string, not a Date object.
Regards,
Anup
All Answers
Hey raj123,
I am not clear as to what the issue is.
Can you elaborate the following?
> the date variable is coming as d instead of value when i check in debug logs
Do you mean that the value in variable d is empty?
Also, your SOQL is incorrect I believe. How do you expect this query to return anything when you are checking if the received_date__c is both greater than the value in d, and also null? These two conditions are mutually exclusive.
Regards,
Anup
hi thank for the quick reply
hi i am comparing the received_date__c(date type ) with d which is a date i am preparing to pass to the query, but the date value is not showing insted d is showing up
the whole thing is in the querystring as i am passing the query string to
Database.query(strQuery)
debug logs
Hi,
I have tested the same and its working fine at my end. Try the below as reference:
date d = system.today().addDays(-2);
system.debug('@@@@@@@@@@@@@@@@@@' +d);
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
but if i am using the date variable d in the query string , the date vaule is not ppulating at runtime
Your debug looks like you have a space between the ':' character and the 'd' - is that the case for the code?
i removed the space b/n : and d , still noo success
Ah I see!
Then modify your query string as follows and it should work:
String strQuery='Select Id,Collection_Center_Code__c,RMA_Number__c,Case.Co
ntact.Name,Contact.Email,SC_Received_Num_Boxes_WDE__c,SCReceivedPalleteID_WDE__c,SCReceivedTracking_WDE__c, SCReceivedTime_WDE__c,SCShipToWDDate_WDE__c,(Select Id,Received_Date__c From Order_Status__r where received_date__c > '+d+' and received_date__c = null ) From Case t Where Collection_Center_Code__c =\''+Code+'\'';
hope this helps!
- Anup
ohh, its erroring out
You might have to convert the the value in d to string, and it will work because the query string expects a string, not a Date object.
Regards,
Anup
Your query was wrong this whole time, I think. You have "received_date__c > :d and received_date__c = null" in your filter conditions, which will never be satisified. The debug logs won't show the substituted date value in the bound SOQL statement, but it will work correctly regardless. Try using your original query, using "or" instead of "and", if that is your intent. A field can not possibly ever be null *and* return a true value for any inequality operator, since null is always a false result in an inequality operator.
EDIT: If you're using Database.Query(String), you have to format the date field yourself. Instead, just use the standard SOQL syntax ( [SELECT ... FROM ... WHERE .. ] ), so that salesforce.com can bind it correctly for you. Alternatively, you can bind directly to the variable using:
String query = 'SELECT ... FROM ... WHERE ... Received_date__c > :d ...'
Thanks to the magic of the Database.query runtime engine, it will try and resolve bound variables in a string just as it would were it a static (normal) query.