1

I have list of dates and I have stored them in a set.

List<Account> a=[select id,duedate__c,overduedate__c from account];
Set<Date> sdate=new set<date>();
Set<Date> s1date=new set<date>();
for(Account acc.a){
sdate.add(acc.duedate__c);
sdate1.add(acc.overduedate__c );
}

My sdate: 2017-12-31,2017-12-03 and s1date :2018-12-31,2017-12-04

I am going to insert new account with due date 2018-12-31 and over due date 2018-12-04.

I have fetch a record if these dates falls in any other account.

When I executed the query in developer console, I got the result but I am not getting in apex , the list size is 0.

List<account> asd=[Select id from Account duedate__c<= :sdate and overduedate__c >= :sdate and duedate__c<= :sdate1 and overduedate__c >= : sdate1];

Devloper console Query editor

Select id from Account duedate__c<= :2018-12-31 and overduedate__c >= :2018-12-31 and duedate__c<= :2018-12-04 and overduedate__c >= : 2018-12-04

I got the result. The list size is 1.

Please give me some suggestions.

1 Answer 1

2

According to your query in apex the first criteria is due date must be greater than or equal to sdate set that is {2017-12-31,2017-12-03} and the first criteria for developer console query is duedate__c<= 2018-12-31. And you inserted accounts with due date 2018-12-31 so change the query to following

List<account> asd=[Select id from Account duedate__c<= 2018-12-31 
                                          and overduedate__c >= :sdate 
                                          and duedate__c<= duedate__c<= 2018-12-04 
                                          and overduedate__c >= : sdate1];
2
  • Hi@safiya PV can we compare the date in set like "overduedate__c >= :sdate "
    – moni
    Nov 7, 2018 at 12:02
  • yes you can do. it will check for the same condition with each element of your set with or condition.
    – Safiya PV
    Nov 7, 2018 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .