+ Start a Discussion
sayyed rabbani2sayyed rabbani2 

Hi All, I wanted to query 1 year ahead lead records based on CreatedDate i tried using Last_N_days and Next_N_days but it is not working.. any suggestions from your end.

Hi All, I wanted to query 1 year ahead lead records based on CreatedDate  i tried using Last_N_days and Next_N_days but it is not working.. any suggestions from your end.

Quick reply helps me to use it in my code.

Thanks
Sayyed
SandhyaSandhya (Salesforce Developers) 
Hi,

This query worked for me 
 
Select * from lead where WHERE CreatedDate = LAST_N_DAYS:365
Please refer below link

http://www.simplysfdc.com/2013/11/salesforce-soql-lastweek-lastndaysn-and.html

Hope this helps you!

If this helps you please mark it as solved.

Thanks and Regards
Sandhya
Sergio AlcocerSergio Alcocer
@Sayyed, I don't see how can you ask salesforce to predict the future (asking for the leads that are going to be created in the future, that might explain why you don't get records using the next_n_days)
@Sandhya, I don't see how a select * or a soql with "where WHERE" can even work
LAST_N_DAYS:{0}
Where {0} should be replaced with the number of days you want.
SandhyaSandhya (Salesforce Developers) 
Hi Sergio Alcocer,

You are right, sorry that's a typo mistake 
SELECT Id, Name, CreatedDate FROM Lead WHERE CreatedDate = LAST_N_DAYS:365

Thanks and Regards
Sandhya