You need to sign in to do that
Don't have an account?

SOQL query returning something when it shouldn't
Hello all,
I have a list of accounts for which I am the product owner. I modified them all today for testing purposes, in order to have my custom field Last_Update__c = today.
In my VF page, I call my custom constructor which does something very simple (please note that I removed the code handling the exceptions for brevity reasons
public Account getAccount() { account = [SELECT Id, Name, Last_Status__c,Additional_Information__c,Ongoing_Problem__c,Last_Update__c FROM Account WHERE (OwnerId = :UserInfo.getUserID()) AND (Type <> 'Dead') AND (Last_Update__c = LAST_N_DAYS:150) ORDER BY Last_Update__c LIMIT 1]; return account; }
The idea should be to retrieve an account only when three conditions are all met. Third one is
Last_Update__c = LAST_N_DAYS:150. In my understanding, this should mean: "select an account if Last Update was done more than 150 days ago". However, I get every account in the list as a result, even if they all have today as last_update__c field. What am I doing wrong?
Thanks in advance for your help on this.
Cheers, A.
All Answers
Using LAST_N_DAYS:150 in SOQL will return all records where the date starts from 12:00:00 AM (user Local Time Zone) of the current day and continues for the last 150 days. So it is basically a rage. Start data is 150 days ago and end date is today.
Check out this site, it has some good details about using date filtes in SOQL: http://simplysfdc.blogspot.com/2013/11/salesforce-soql-lastweek-lastndaysn-and.html
Art.