You need to sign in to do that
Don't have an account?
pavan kumar 177
Unable to calculate days in apex
I need to calculate days between two fields.
So I use daysBetween to complete when I try to do with two dates it's working fine.
But, when I try with list(or) map it throws an error like:
Method does not exist or incorrect signature: [Date].daysBetween(List)
For reference my code:
public date closedates;
Public Long details;
List<Case> c=new List<case>();
List<Integer> Values=new List<Integer>();
//Integer Value=0;
List<Date> Churndate=new List<Date>();
List<Date> closedatesd=new List<Date>();
c=[Select Id,Date_Order_Received__c,accountId from case where RecordTypeId = '01290000000sF3L'];
System.debug('Data in Case '+c);
List<Id> accountIds= new List<Id>();
List<Account> accounts=new List<Account>();
List<Id> opps=new List<Id>();
List<Date> Oppsdate= new List<Date>();
for(Case cl:c) {
accountIds.add(cl.accountId);
//Churndate=cl.Date_Order_Received__c;
Churndate.add(cl.Date_Order_Received__c);
}
System.debug('Date value in '+churndate);
for(Account ao:[Select Id,name,(select Id,name,CloseDate from opportunities) from account where Id in:accountIds]) {
for(Opportunity opp : ao.opportunities) {
opps.add(opp.Id);
//details=closedates.daysBetween(Churndate);
**Values.add(opp.CloseDate.daysBetween(Churndate));**
//Other Operation you want to perform with every opportunity
}
}
So I use daysBetween to complete when I try to do with two dates it's working fine.
But, when I try with list(or) map it throws an error like:
Method does not exist or incorrect signature: [Date].daysBetween(List)
For reference my code:
public date closedates;
Public Long details;
List<Case> c=new List<case>();
List<Integer> Values=new List<Integer>();
//Integer Value=0;
List<Date> Churndate=new List<Date>();
List<Date> closedatesd=new List<Date>();
c=[Select Id,Date_Order_Received__c,accountId from case where RecordTypeId = '01290000000sF3L'];
System.debug('Data in Case '+c);
List<Id> accountIds= new List<Id>();
List<Account> accounts=new List<Account>();
List<Id> opps=new List<Id>();
List<Date> Oppsdate= new List<Date>();
for(Case cl:c) {
accountIds.add(cl.accountId);
//Churndate=cl.Date_Order_Received__c;
Churndate.add(cl.Date_Order_Received__c);
}
System.debug('Date value in '+churndate);
for(Account ao:[Select Id,name,(select Id,name,CloseDate from opportunities) from account where Id in:accountIds]) {
for(Opportunity opp : ao.opportunities) {
opps.add(opp.Id);
//details=closedates.daysBetween(Churndate);
**Values.add(opp.CloseDate.daysBetween(Churndate));**
//Other Operation you want to perform with every opportunity
}
}
1) Create (and somehow maintain) the relationship from the Case to the Opportunity
2) Get to AN Opportunity through the account.
You might try some code close to this. (I didn't do your selects on the exact case, etc) But this should give you a concept of how to do it.
@JeffreyStevens