Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4002,4 +4002,25 @@ private class MockDatabaseTest {

Assert.areEqual(24, opportunities.size(), 'Incorrect number of opportunities');
}

@isTest
static void ensureNextFiscalYearWorksInWhereClause() {

List<Opportunity> oppList = new List<Opportunity>();
Date startOfYear = Date.newInstance(Gmt.today().year(), 1, 1);
for(Integer i = 0; i < 36; i++) {
oppList.add(new Opportunity(
Name = 'Opp' + i,
CloseDate = startOfYear.addMonths(i)
));
}

MockDatabase.doInsert(oppList, true);

Test.startTest();
List<Opportunity> opportunities = MockDatabase.query('SELECT Id FROM Opportunity WHERE CloseDate = NEXT_FISCAL_YEAR');
Test.stopTest();

Assert.areEqual(12, opportunities.size(), 'Incorrect number of opportunities');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public abstract class DateLiteralComparable {
* @param fieldValue `DateTime`
* @return `Boolean`
*/
public abstract Boolean isEqual(DateTime fieldValue);
public virtual Boolean isEqual(DateTime fieldValue) {
return !isGreaterThan(fieldValue) && !isLessThan(fieldValue);
}
/**
* @description Whether the date literal is greater than the field value
* @param fieldValue `DateTime`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public with sharing class DateLiteralComparableFactory {
Token.LAST_QUARTER_LITERAL => LastQuarterComparable.class,
Token.NEXT_QUARTER_LITERAL => NextQuarterComparable.class,
Token.NEXT_N_QUARTERS_LITERAL => NextNQuartersComparable.class,
Token.NEXT_FISCAL_YEAR_LITERAL => NextFiscalYearComparable.class,
Token.THIS_YEAR_LITERAL => ThisYearComparable.class,
Token.THIS_FISCAL_YEAR_LITERAL => ThisFiscalYearComparable.class,
Token.LAST_N_FISCAL_YEARS_LITERAL => LastNFiscalYearsComparable.class
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @description Comparable for the NEXT_FISCAL_YEAR date literal
* @author Zackary Frazier
* @since 1/9/2025
*/
public with sharing class NextFiscalYearComparable extends DateLiteralComparable {
/**
* @description Return whether fieldValue is less than the start of the next fiscal year
* @param fieldValue `Datetime`
* @return `Boolean`
*/
public override Boolean isLessThan(Datetime fieldValue) {
Date startOfNextFiscalYear = Gmt.startOfThisFiscalYear().addYears(1);
return fieldValue < startOfNextFiscalYear;
}

/**
* @description Return whether fieldValue is greater than the start of the next fiscal year
* @param fieldValue `Datetime`
* @return `Boolean`
*/
public override Boolean isGreaterThan(Datetime fieldValue) {
Date startOfNextFiscalYear = Gmt.startOfThisFiscalYear().addYears(1);
return fieldValue >= startOfNextFiscalYear.addYears(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@isTest
private class NextFiscalYearComparableTest {

@isTest
static void ensureIsLessThanWorks() {
DateLiteralComparable nextFiscalYearComparable = new NextFiscalYearComparable().withToken('NEXT_FISCAL_YEAR');

Assert.isTrue(nextFiscalYearComparable.isLessThan(Gmt.startOfThisFiscalYear()), 'Should be less than');
Assert.isFalse(nextFiscalYearComparable.isLessThan(Gmt.startOfThisFiscalYear().addYears(1)), 'Should not be less than');
Assert.isFalse(nextFiscalYearComparable.isLessThan(Gmt.startOfThisFiscalYear().addYears(2)), 'Should not be less than');
}

@isTest
static void ensureIsGreaterThanWorks() {
DateLiteralComparable nextFiscalYearComparable = new NextFiscalYearComparable().withToken('NEXT_FISCAL_YEAR');

Assert.isFalse(nextFiscalYearComparable.isGreaterThan(Gmt.startOfThisFiscalYear()), 'Should not be greater than');
Assert.isFalse(nextFiscalYearComparable.isGreaterThan(Gmt.startOfThisFiscalYear().addYears(1)), 'Should not be greater than');
Assert.isTrue(nextFiscalYearComparable.isGreaterThan(Gmt.startOfThisFiscalYear().addYears(2)), 'Should be greater than');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,17 @@ private class ParserTest {
}
Test.stopTest();
}

@isTest
static void ensureNextFiscalYearCanBeParsed() {
Parser p = new Parser();
String soqlQuery = 'SELECT Id FROM Opportunity WHERE CreatedDate = NEXT_FISCAL_YEAR';
Test.startTest();
try {
p.parse(soqlQuery);
} catch(Exception e) {
Assert.fail('Expected no exception but got ' + e.getMessage() + ' for ' + soqlQuery);
}
Test.stopTest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public with sharing class PrimitiveParserFactory {
Token.NEXT_N_QUARTERS_LITERAL => NextNQuartersParser.class,
Token.THIS_FISCAL_YEAR_LITERAL => ThisFiscalYearParser.class,
Token.LAST_N_FISCAL_YEARS_LITERAL => LastNFiscalYearsParser.class,
Token.NEXT_FISCAL_YEAR_LITERAL => NextFiscalYearParser.class,
Token.THIS_YEAR_LITERAL => ThisYearParser.class,
Token.XTRUE => BooleanParser.class,
Token.XFALSE => BooleanParser.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @description Parser for the NEXT_FISCAL_YEAR date literal
* @author Zackary Frazier
* @since 1/9/2025
*/
public with sharing class NextFiscalYearParser extends DateLiteralParser {
/**
* @description Parses the NEXT_FISCAL_YEAR date literal
* @param query `String`
* @return `Intermediary`
*/
public override Intermediary parse(String query) {
return parse(query, Token.NEXT_FISCAL_YEAR_LITERAL);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@isTest
private class NextFiscalYearParserTest {

@isTest
static void ensureNextFiscalYearIsParseable() {
DateLiteralParser nextFiscalYearParser = new NextFiscalYearParser();
Intermediary intermediary = nextFiscalYearParser.parse('NEXT_FISCAL_YEAR');

Assert.areEqual(Token.NEXT_FISCAL_YEAR_LITERAL, intermediary.head.id, 'Should be a NEXT_FISCAL_YEAR token');
Assert.areEqual(NodeType.DATE_LITERAL, intermediary.head.nodeType, 'Should be a DATE_LITERAL node');
Assert.isNull(intermediary.head.left, 'Should not have a left');
Assert.isNull(intermediary.head.right, 'Should not have a right');
Assert.areEqual('', intermediary.subquery, 'Subquery should be empty');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@ public inherited sharing class Token {
public final static String THIS_YEAR_LITERAL = 'this_year';
public final static String THIS_FISCAL_YEAR_LITERAL = 'this_fiscal_year';
public final static String LAST_N_FISCAL_YEARS_LITERAL = 'last_n_fiscal_years';
public final static String NEXT_FISCAL_YEAR_LITERAL = 'next_fiscal_year';
}
Loading