File tree Expand file tree Collapse file tree 8 files changed +120
-2
lines changed
moxygen/main/default/classes/database
interpreter/operator-handler/date-literal-comparable Expand file tree Collapse file tree 8 files changed +120
-2
lines changed Original file line number Diff line number Diff line change @@ -7309,4 +7309,32 @@ private class MockDatabaseTest {
7309
7309
' Incorrect number of opportunities'
7310
7310
);
7311
7311
}
7312
+
7313
+ @isTest
7314
+ static void ensureThisFiscalQuarterWorksInWhereClause () {
7315
+ List <Opportunity > oppList = new List <Opportunity >();
7316
+ Date startOfThisFiscalQuarter = Gmt .startOfThisFiscalQuarter ();
7317
+ for (Integer i = 0 ; i < 36 ; i ++ ) {
7318
+ oppList .add (
7319
+ new Opportunity (
7320
+ Name = ' Opp' + i ,
7321
+ CloseDate = startOfThisFiscalQuarter .addMonths (i )
7322
+ )
7323
+ );
7324
+ }
7325
+
7326
+ MockDatabase .doInsert (oppList , true );
7327
+
7328
+ Test .startTest ();
7329
+ List <Opportunity > opportunities = MockDatabase .query (
7330
+ ' SELECT Id, CloseDate FROM Opportunity WHERE CloseDate = THIS_FISCAL_QUARTER'
7331
+ );
7332
+ Test .stopTest ();
7333
+
7334
+ Assert .areEqual (
7335
+ 3 ,
7336
+ opportunities .size (),
7337
+ ' Incorrect number of opportunities'
7338
+ );
7339
+ }
7312
7340
}
Original file line number Diff line number Diff line change @@ -156,6 +156,7 @@ public with sharing class Token {
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
158
public final static String LAST_FISCAL_QUARTER = ' last_fiscal_quarter' ;
159
+ public final static String THIS_FISCAL_QUARTER = ' this_fiscal_quarter' ;
159
160
160
161
public final static Set <String > DATE_LITERAL_TOKENS = new Set <String >{
161
162
TODAY_LITERAL ,
@@ -190,6 +191,7 @@ public with sharing class Token {
190
191
LAST_N_FISCAL_QUARTERS ,
191
192
NEXT_FISCAL_QUARTER ,
192
193
NEXT_N_FISCAL_QUARTERS ,
193
- LAST_FISCAL_QUARTER
194
+ LAST_FISCAL_QUARTER ,
195
+ THIS_FISCAL_QUARTER
194
196
};
195
197
}
Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ public with sharing class DateLiteralComparableFactory {
38
38
Token .LAST_N_FISCAL_QUARTERS = > LastNFiscalQuartersComparable .class ,
39
39
Token .NEXT_FISCAL_QUARTER = > NextFiscalQuarterComparable .class ,
40
40
Token .NEXT_N_FISCAL_QUARTERS = > NextNFiscalQuartersComparable .class ,
41
- Token .LAST_FISCAL_QUARTER = > LastFiscalQuarterComparable .class
41
+ Token .LAST_FISCAL_QUARTER = > LastFiscalQuarterComparable .class ,
42
+ Token .THIS_FISCAL_QUARTER = > ThisFiscalQuarterComparable .class
42
43
};
43
44
44
45
@TestVisible
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @description Comparable class for THIS_FISCAL_QUARTER
3
+ * @author Zackary Frazier
4
+ * @since 2/2/2025
5
+ */
6
+ public with sharing class ThisFiscalQuarterComparable extends DateLiteralComparable {
7
+ public override Boolean isLessThan (Datetime fieldValue ) {
8
+ Date startOfThisFiscalQuarter = Gmt .startOfThisFiscalQuarter ();
9
+ return fieldValue < startOfThisFiscalQuarter ;
10
+ }
11
+
12
+ public override Boolean isGreaterThan (Datetime fieldValue ) {
13
+ Date startOfThisFiscalQuarter = Gmt .startOfThisFiscalQuarter ();
14
+ Date startOfNextFiscalQuarter = startOfThisFiscalQuarter .addMonths (3 );
15
+ return fieldValue >= startOfNextFiscalQuarter ;
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 ThisFiscalQuarterComparableTest {
3
+ @isTest
4
+ static void ensureIsLessThanWorks () {
5
+ Date startOfThisFiscalQuarter = Gmt .startOfThisFiscalQuarter ();
6
+ Date startOfThisFiscalQuarterMinusOneDay = startOfThisFiscalQuarter .addDays (
7
+ - 1
8
+ );
9
+
10
+ ThisFiscalQuarterComparable dateLiteralComparable = new ThisFiscalQuarterComparable ();
11
+
12
+ Assert .isTrue (
13
+ dateLiteralComparable .isLessThan (
14
+ startOfThisFiscalQuarterMinusOneDay
15
+ ),
16
+ ' Start of this fiscal quarter minus one day should be less than the this fiscal quarter'
17
+ );
18
+
19
+ Assert .isFalse (
20
+ dateLiteralComparable .isLessThan (startOfThisFiscalQuarter ),
21
+ ' Start of this fiscal quarter should not be less than the this fiscal quarter'
22
+ );
23
+ }
24
+
25
+ @isTest
26
+ static void ensureIsGreaterThanWorks () {
27
+ Date startOfThisFiscalQuarter = Gmt .startOfThisFiscalQuarter ();
28
+ Date startOfNextFiscalQuarter = startOfThisFiscalQuarter .addMonths (3 );
29
+
30
+ ThisFiscalQuarterComparable dateLiteralComparable = new ThisFiscalQuarterComparable ();
31
+
32
+ Assert .isTrue (
33
+ dateLiteralComparable .isGreaterThan (startOfNextFiscalQuarter ),
34
+ ' Start of next fiscal quarter should be greater than the this fiscal quarter'
35
+ );
36
+
37
+ Assert .isFalse (
38
+ dateLiteralComparable .isGreaterThan (startOfThisFiscalQuarter ),
39
+ ' Start of this fiscal quarter should not be greater than the this fiscal quarter'
40
+ );
41
+ }
42
+ }
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 @@ -806,4 +806,22 @@ private class ParserTest {
806
806
}
807
807
Test .stopTest ();
808
808
}
809
+
810
+ @isTest
811
+ static void ensureThisFiscalQuarterCanBeParsed () {
812
+ Parser p = new Parser ();
813
+ String soqlQuery = ' SELECT Id FROM Opportunity WHERE CreatedDate = THIS_FISCAL_QUARTER' ;
814
+ Test .startTest ();
815
+ try {
816
+ p .parse (soqlQuery );
817
+ } catch (Exception e ) {
818
+ Assert .fail (
819
+ ' Expected no exception but got ' +
820
+ e .getMessage () +
821
+ ' for ' +
822
+ soqlQuery
823
+ );
824
+ }
825
+ Test .stopTest ();
826
+ }
809
827
}
You can’t perform that action at this time.
0 commit comments