Skip to content

Commit 0016af1

Browse files
committed
Add method to include ALL ROWS in QueryFactory
1 parent c7ee215 commit 0016af1

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

sfdx-source/apex-common/main/classes/fflib_QueryFactory.cls

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
7474
private Boolean enforceFLS;
7575

7676
private Boolean sortSelectFields = true;
77+
private Boolean allRows = false;
7778

7879
/**
7980
* The relationship and subselectQueryMap variables are used to support subselect queries. Subselects can be added to
@@ -662,6 +663,14 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
662663
return setOrdering(ordr);
663664
}
664665

666+
/**
667+
* @param addAllRows whether an ALL ROWS clause will be added to the resulting query.
668+
**/
669+
public fflib_QueryFactory setAllRows(Boolean addAllRows){
670+
this.allRows = addAllRows;
671+
return this;
672+
}
673+
665674
/**
666675
* Convert the values provided to this instance into a full SOQL string for use with Database.query
667676
* Check to see if subqueries queries need to be added after the field list.
@@ -703,6 +712,9 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
703712

704713
if(offsetCount != null)
705714
result += ' OFFSET '+offsetCount;
715+
716+
if(allRows)
717+
result += ' ALL ROWS';
706718

707719
return result;
708720
}
@@ -716,6 +728,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
716728
fflib_QueryFactory clone = new fflib_QueryFactory(this.table)
717729
.setLimit(this.limitCount)
718730
.setOffset(this.offsetCount)
731+
.setAllRows(this.allRows)
719732
.setCondition(this.conditionExpression)
720733
.setEnforceFLS(this.enforceFLS);
721734

sfdx-source/apex-common/test/classes/fflib_QueryFactoryTest.cls

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ private class fflib_QueryFactoryTest {
564564
.selectField('Description')
565565
.addOrdering(new fflib_QueryFactory.Ordering('Contact','name',fflib_QueryFactory.SortOrder.ASCENDING) )
566566
.addOrdering( new fflib_QueryFactory.Ordering('Contact','CreatedDATE',fflib_QueryFactory.SortOrder.DESCENDING))
567+
.setAllRows(true)
567568
.setEnforceFLS(true);
568569

569570
fflib_QueryFactory qf2 = qf.deepClone();
@@ -584,6 +585,7 @@ private class fflib_QueryFactoryTest {
584585
.selectField('Description')
585586
.addOrdering(new fflib_QueryFactory.Ordering('Account','Name',fflib_QueryFactory.SortOrder.ASCENDING) )
586587
.addOrdering( new fflib_QueryFactory.Ordering('Account','Description',fflib_QueryFactory.SortOrder.DESCENDING))
588+
.setAllRows(true)
587589
.setEnforceFLS(true);
588590

589591
qf.subselectQuery('Contacts', true);
@@ -607,6 +609,7 @@ private class fflib_QueryFactoryTest {
607609
.selectField('Description')
608610
.addOrdering(new fflib_QueryFactory.Ordering('Contact','name',fflib_QueryFactory.SortOrder.ASCENDING) )
609611
.addOrdering( new fflib_QueryFactory.Ordering('Contact','CreatedDATE',fflib_QueryFactory.SortOrder.DESCENDING))
612+
.setAllRows(true)
610613
.setEnforceFLS(true);
611614

612615

@@ -693,6 +696,24 @@ private class fflib_QueryFactoryTest {
693696
System.assertNotEquals(orderedQuery, actualSoql);
694697
}
695698

699+
@isTest
700+
static void testSoql_allRows(){
701+
//Given
702+
fflib_QueryFactory qf = new fflib_QueryFactory(User.SObjectType);
703+
qf.selectField('Id');
704+
qf.setAllRows(true);
705+
706+
String allRowsQuery =
707+
'SELECT Id '
708+
+'FROM User '
709+
+'ALL ROWS';
710+
711+
//When
712+
String actualSoql = qf.toSOQL();
713+
714+
//Then
715+
System.assertEquals(allRowsQuery, actualSoql);
716+
}
696717

697718
public static User createTestUser_noAccess(){
698719
User usr;

0 commit comments

Comments
 (0)