Here I am doing an aggregate SOQL
List<AggregateResult> ListName = [select SUM(Field1__c), SUM(Field2__c),
from CustomObject__c
where Object2__r.Id In :List2
AND ( createdDate>=: StartDateQuarter
AND createdDate<=: EndDateQuarter )
GROUP BY Object2__r.Name, Object2__r.Id ];
This is where I am determining the dates.
List<Period> LastDates = [Select type, StartDate, EndDate From Period WHERE type = 'Quarter' AND StartDate = LAST_N_QUARTERS:4 LIMIT 1];
Datetime StartDateQuarterLast = LastDates[0].StartDate;
Datetime EndDateQuarterLast = LastDates[0].EndDate;
This query is working when I am removing the DATE part. NOT working with the DATE filter.
StartDateQuarter and EndDateQuarter are getting values. I have checked that.
Is there any syntactical error?
QuartertoCreatedDate. – crmprogdev May 13 '16 at 14:52String formattedDt = dt.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');should dod the trick, or you can even tryformatGmt(dateFormatString)from here – o-lexi May 13 '16 at 16:09value of filter criterion for field 'CreatedDate' must be of type dateTime and should not be enclosed in quotes, soDateTime.newInstanceGMT(LastDates[0].StartDate, Time.newInstance(0, 0, 0, 0));should work – o-lexi May 13 '16 at 17:02