5

Hi friends i'm new to development, and I have a requirement to write a sample query to fetch data in cases for a particular record type.

I fetch accountIds from cases. Then, I fetch opportunity id's from from account.

But my problem is there is a field called "Date_Order_Received__c" in cases.So i have to filter the records based on date field in case and any opportunity closed won with "Closedate" with in 180 days(Between both fields).

My sample code

List<Case> c=new List<Case>();
public date Churndate;
//List<Date> Churndate=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>();
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(Opportunity opp :[Select Id, Name from Opportunity Where accountId in:accountIds]) {
    opps.add(opp.Id);
}

1 Answer 1

17

You can use Apex provided Date class method daysBetween:

Example:

Date startDate = Date.newInstance(2008, 1, 1);
Date dueDate = Date.newInstance(2008, 1, 30);
Integer numberDaysDue = startDate.daysBetween(dueDate);

You must log in to answer this question.

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