Skip to content

Commit a64b4a2

Browse files
Merge pull request #409 from 1903Daniel/all-rows-in-query-factory
Add method to include ALL ROWS in QueryFactory
2 parents a56f0f1 + bfe8a47 commit a64b4a2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-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+
* whether an ALL ROWS clause will be added to the resulting query
668+
**/
669+
public fflib_QueryFactory setAllRows(){
670+
this.allRows = true;
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,10 @@ 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';
718+
}
706719

707720
return result;
708721
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,24 @@ private class fflib_QueryFactoryTest {
693693
System.assertNotEquals(orderedQuery, actualSoql);
694694
}
695695

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

697715
public static User createTestUser_noAccess(){
698716
User usr;

0 commit comments

Comments
 (0)