File tree Expand file tree Collapse file tree 8 files changed +122
-2
lines changed
moxygen/main/default/classes/database
interpreter/operator-handler/date-literal-comparable Expand file tree Collapse file tree 8 files changed +122
-2
lines changed Original file line number Diff line number Diff line change @@ -7281,4 +7281,32 @@ private class MockDatabaseTest {
7281
7281
' Incorrect number of opportunities'
7282
7282
);
7283
7283
}
7284
+
7285
+ @isTest
7286
+ static void ensureLastFiscalQuarterWorksInWhereClause () {
7287
+ List <Opportunity > oppList = new List <Opportunity >();
7288
+ Date startOfThisFiscalQuarter = Gmt .startOfThisFiscalQuarter ();
7289
+ for (Integer i = 0 ; i < 36 ; i ++ ) {
7290
+ oppList .add (
7291
+ new Opportunity (
7292
+ Name = ' Opp' + i ,
7293
+ CloseDate = startOfThisFiscalQuarter .addMonths (- i )
7294
+ )
7295
+ );
7296
+ }
7297
+
7298
+ MockDatabase .doInsert (oppList , true );
7299
+
7300
+ Test .startTest ();
7301
+ List <Opportunity > opportunities = MockDatabase .query (
7302
+ ' SELECT Id, CloseDate FROM Opportunity WHERE CloseDate = LAST_FISCAL_QUARTER'
7303
+ );
7304
+ Test .stopTest ();
7305
+
7306
+ Assert .areEqual (
7307
+ 3 ,
7308
+ opportunities .size (),
7309
+ ' Incorrect number of opportunities'
7310
+ );
7311
+ }
7284
7312
}
Original file line number Diff line number Diff line change @@ -155,6 +155,7 @@ public with sharing class Token {
155
155
public final static String LAST_N_FISCAL_QUARTERS = ' last_n_fiscal_quarters' ;
156
156
public final static String NEXT_FISCAL_QUARTER = ' next_fiscal_quarter' ;
157
157
public final static String NEXT_N_FISCAL_QUARTERS = ' next_n_fiscal_quarters' ;
158
+ public final static String LAST_FISCAL_QUARTER = ' last_fiscal_quarter' ;
158
159
159
160
public final static Set <String > DATE_LITERAL_TOKENS = new Set <String >{
160
161
TODAY_LITERAL ,
@@ -188,6 +189,7 @@ public with sharing class Token {
188
189
N_YEARS_AGO ,
189
190
LAST_N_FISCAL_QUARTERS ,
190
191
NEXT_FISCAL_QUARTER ,
191
- NEXT_N_FISCAL_QUARTERS
192
+ NEXT_N_FISCAL_QUARTERS ,
193
+ LAST_FISCAL_QUARTER
192
194
};
193
195
}
Original file line number Diff line number Diff line change @@ -37,7 +37,8 @@ public with sharing class DateLiteralComparableFactory {
37
37
Token .N_YEARS_AGO = > NYearsAgoComparable .class ,
38
38
Token .LAST_N_FISCAL_QUARTERS = > LastNFiscalQuartersComparable .class ,
39
39
Token .NEXT_FISCAL_QUARTER = > NextFiscalQuarterComparable .class ,
40
- Token .NEXT_N_FISCAL_QUARTERS = > NextNFiscalQuartersComparable .class
40
+ Token .NEXT_N_FISCAL_QUARTERS = > NextNFiscalQuartersComparable .class ,
41
+ Token .LAST_FISCAL_QUARTER = > LastFiscalQuarterComparable .class
41
42
};
42
43
43
44
@TestVisible
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @description Comparable class for LAST_FISCAL_QUARTER
3
+ * @author Zackary Frazier
4
+ * @since 2/2/2025
5
+ */
6
+ public with sharing class LastFiscalQuarterComparable extends DateLiteralComparable {
7
+ public override Boolean isLessThan (Datetime fieldValue ) {
8
+ Date startOfThisFiscalQuarter = Gmt .startOfthisFiscalQuarter ();
9
+ Date startOfLastFiscalQuarter = startOfThisFiscalQuarter .addMonths (- 3 );
10
+ return fieldValue < startOfLastFiscalQuarter ;
11
+ }
12
+
13
+ public override Boolean isGreaterThan (Datetime fieldValue ) {
14
+ Date startOfThisFiscalQuarter = Gmt .startOfThisFiscalQuarter ();
15
+ return fieldValue >= startOfThisFiscalQuarter ;
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <ApexClass xmlns =" http://soap.sforce.com/2006/04/metadata" >
3
+ <apiVersion >62.0</apiVersion >
4
+ <status >Active</status >
5
+ </ApexClass >
Original file line number Diff line number Diff line change
1
+ @isTest
2
+ private class LastFiscalQuarterComparableTest {
3
+ @isTest
4
+ static void ensureIsLessThanWorks () {
5
+ LastFiscalQuarterComparable dateLiteralComparable = new LastFiscalQuarterComparable ();
6
+ Date startOfThisFiscalQuarter = Gmt .startOfthisFiscalQuarter ();
7
+ Date startOfLastFiscalQuarter = startOfThisFiscalQuarter .addMonths (- 3 );
8
+ Date startOfLastFiscalQuarterMinusOneDay = startOfLastFiscalQuarter .addDays (
9
+ - 1
10
+ );
11
+ Assert .isTrue (
12
+ dateLiteralComparable .isLessThan (
13
+ startOfLastFiscalQuarterMinusOneDay
14
+ ),
15
+ ' Start of last fiscal quarter minus one day should be less than the last fiscal quarter'
16
+ );
17
+
18
+ Assert .isFalse (
19
+ dateLiteralComparable .isLessThan (startOfLastFiscalQuarter ),
20
+ ' Start of last fiscal quarter should not be less than the last fiscal quarter'
21
+ );
22
+ }
23
+
24
+ @isTest
25
+ static void ensureIsGreaterThanWorks () {
26
+ LastFiscalQuarterComparable dateLiteralComparable = new LastFiscalQuarterComparable ();
27
+ Date startOfThisFiscalQuarter = Gmt .startOfthisFiscalQuarter ();
28
+ Date startOfThisFiscalQuarterMinusOne = startOfThisFiscalQuarter .addDays (
29
+ - 1
30
+ );
31
+
32
+ Assert .isFalse (
33
+ dateLiteralComparable .isGreaterThan (
34
+ startOfThisFiscalQuarterMinusOne
35
+ ),
36
+ ' Start of this fiscal quarter minus one day should not be greater than the last fiscal quarter'
37
+ );
38
+
39
+ Assert .isTrue (
40
+ dateLiteralComparable .isGreaterThan (startOfThisFiscalQuarter ),
41
+ ' Start of this fiscal quarter should be greater than the last fiscal quarter'
42
+ );
43
+ }
44
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <ApexClass xmlns =" http://soap.sforce.com/2006/04/metadata" >
3
+ <apiVersion >62.0</apiVersion >
4
+ <status >Active</status >
5
+ </ApexClass >
Original file line number Diff line number Diff line change @@ -788,4 +788,22 @@ private class ParserTest {
788
788
}
789
789
Test .stopTest ();
790
790
}
791
+
792
+ @isTest
793
+ static void ensureLastFiscalQuarterCanBeParsed () {
794
+ Parser p = new Parser ();
795
+ String soqlQuery = ' SELECT Id FROM Opportunity WHERE CreatedDate = LAST_FISCAL_QUARTER' ;
796
+ Test .startTest ();
797
+ try {
798
+ p .parse (soqlQuery );
799
+ } catch (Exception e ) {
800
+ Assert .fail (
801
+ ' Expected no exception but got ' +
802
+ e .getMessage () +
803
+ ' for ' +
804
+ soqlQuery
805
+ );
806
+ }
807
+ Test .stopTest ();
808
+ }
791
809
}
You can’t perform that action at this time.
0 commit comments