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
Yogendra RishishwarYogendra Rishishwar 

> LAST_N_DAYS:n not working in SOQL

If I am using below Query
SELECT CaseNumber from Case where  ClosedDate > LAST_N_DAYS:31

To get all case numbers  which have been closed within last 30 days , It is not giving any result , even though Some cases exist in Database closed within the 30 days.

I could not understand , why I am not getting correct result.
Thanks
Yogendra Rishishwar
 
Best Answer chosen by Yogendra Rishishwar
Paul_BoikoPaul_Boiko
Hi Yogendara,
Try this
 
SELECT CaseNumber from Case where  ClosedDate = LAST_N_DAYS:31

 

All Answers

Paul_BoikoPaul_Boiko
Hi Yogendara,
Try this
 
SELECT CaseNumber from Case where  ClosedDate = LAST_N_DAYS:31

 
This was selected as the best answer
Yogendra RishishwarYogendra Rishishwar
Thanks It is working . Regards Rishishwar
Amit Chaudhary 8Amit Chaudhary 8
You can try LAST_N_DAYS:n
Select CaseNumber from Case where ClosedDate = LAST_N_DAYS:30
Please check below link for more detail
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm

 
anil Kumaranil Kumar
Hi All,

I am trying to use custom label value in SOQL Query. Query is not accepting custom label value. it is expecting number. 

Integer num_days = Integer.valueOf(System.Label.Num_of_Days);
Select id, name FROM contact WHERE LastModifiedDate >= LAST_N_DAYS :num_days 

Thanks,
Anil Kumar
sibil joesibil joe
Hi Anil,

Try to convert to String and do it.
 
Integer n = 31;
String s = 'SELECT Id FROM Account WHERE CreatedDate >= LAST_N_DAYS:'+n;
    List<Account> acc1 = database.query(s);

Thanks