From 36621d5031e466d87416498c856557ee854b2d37 Mon Sep 17 00:00:00 2001 From: Jonny Alexander Power Date: Thu, 13 Apr 2017 15:14:21 -0700 Subject: [PATCH] Add offsetCount to fflib_QueryFactory - Getter / setter for offsetCount (replaces offset) - Deep clone set offset - Add offset clause to generated SOQL string --- fflib/src/classes/fflib_QueryFactory.cls | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/fflib/src/classes/fflib_QueryFactory.cls b/fflib/src/classes/fflib_QueryFactory.cls index 770474c818d..8711089305f 100644 --- a/fflib/src/classes/fflib_QueryFactory.cls +++ b/fflib/src/classes/fflib_QueryFactory.cls @@ -64,7 +64,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr private Set fields; private String conditionExpression; private Integer limitCount; - private Integer offset; + private Integer offsetCount; private List order; /** * Integrate checking for READ Field Level Security within the selectField(s) methods @@ -318,6 +318,19 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr public Integer getLimit(){ return this.limitCount; } + /** + * @param offsetCount if not null causes a OFFSET caluse to be added to the resulting query. + **/ + public fflib_QueryFactory setOffset(Integer offsetCount){ + this.offsetCount = offsetCount; + return this; + } + /** + * @returns the current value of the OFFSET clause, if any. + **/ + public Integer getOffset(){ + return this.offsetCount; + } /** * @param o an instance of {@link fflib_QueryFactory.Ordering} to be added to the query's ORDER BY clause. **/ @@ -589,6 +602,10 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr if(limitCount != null) result += ' LIMIT '+limitCount; + + if(offsetCount != null) + result += ' OFFSET '+offsetCount; + return result; } @@ -600,6 +617,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr fflib_QueryFactory clone = new fflib_QueryFactory(this.table) .setLimit(this.limitCount) + .setOffset(this.offsetCount) .setCondition(this.conditionExpression) .setEnforceFLS(this.enforceFLS); @@ -675,4 +693,4 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr public class InvalidFieldSetException extends Exception{} public class NonReferenceFieldException extends Exception{} public class InvalidSubqueryRelationshipException extends Exception{} -} \ No newline at end of file +}