You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @returns the current value of the OFFSET clause, if any.
359
+
**/
360
+
publicIntegergetOffset(){
361
+
returnthis.offsetCount;
362
+
}
350
363
/**
351
364
* @paramo an instance of {@link fflib_QueryFactory.Ordering} to be added to the query's ORDER BY clause.
352
365
**/
353
366
publicfflib_QueryFactoryaddOrdering(Orderingo){
354
367
this.order.add(o);
355
368
returnthis;
356
369
}
370
+
371
+
/**
372
+
* @paramo an instance of {@link fflib_QueryFactory.Ordering} to remove all existing (for instance defaults) and be added to the query's ORDER BY clause.
373
+
**/
374
+
publicfflib_QueryFactorysetOrdering(Orderingo){
375
+
this.order=newList<Ordering>{ o };
376
+
returnthis;
377
+
}
357
378
/**
358
379
* @returns the list of orderings that will be used as the query's ORDER BY clause. You may remove elements from the returned list, or otherwise mutate it, to remove previously added orderings.
359
380
**/
@@ -580,6 +601,68 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
580
601
returnthis;
581
602
}
582
603
604
+
/**
605
+
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
606
+
* related through an object lookup or master-detail relationship.
607
+
* Use the set to store unique field names, since we only want to sort
608
+
* by the same field one time. The sort expressions are stored in a list
609
+
* so that they are applied to the SOQL in the same order that they
610
+
* were added in.
611
+
* @paramfieldName The string value of the field to be sorted on
612
+
* @paramSortOrder the direction to be sorted on (ASCENDING or DESCENDING)
613
+
* @paramnullsLast whether to sort null values last (NULLS LAST keyword included).
System.assertEquals(1, qf.getOrderings().size(), 'Unexpected order size - setOrder should replace default Orderings');
175
+
System.assertEquals(Contact.OwnerId.getDescribe().getName(), qf.getOrderings()[0].getField(), 'Unexpected order field - should have been resolved from the field OwnerId');
176
+
System.assertEquals(fflib_QueryFactory.SortOrder.DESCENDING, qf.getOrderings()[0].getDirection(), 'Unexpected order direction.');
177
+
178
+
//test method overload with ordering by LastModifiedDate Ascending
System.assertEquals(1, qf.getOrderings().size(), 'Unexpected order size - setOrder should replace previous Orderings');
182
+
System.assertEquals(Contact.LastModifiedDate.getDescribe().getName(), qf.getOrderings()[0].getField(), 'Unexpected order field - should have been resolved from the field LastModifiedDate');
183
+
System.assertEquals(fflib_QueryFactory.SortOrder.ASCENDING, qf.getOrderings()[0].getDirection(), 'Unexpected order direction.');
184
+
185
+
//test method overload with ordering by CreatedDate Descending
System.assertEquals(1, qf.getOrderings().size(), 'Unexpected order size - setOrder should replace previous Orderings');
189
+
System.assertEquals(Contact.CreatedDate.getDescribe().getName(), qf.getOrderings()[0].getField(), 'Unexpected order field - should have been resolved from the field CreatedDate');
190
+
System.assertEquals(fflib_QueryFactory.SortOrder.DESCENDING, qf.getOrderings()[0].getDirection(), 'Unexpected order direction.');
191
+
192
+
//test method overload with ordering by CreatedBy.Name Descending
System.assertEquals(1, qf.getOrderings().size(), 'Unexpected order size - setOrder should replace previous Orderings');
202
+
System.assertEquals(Contact.Birthdate.getDescribe().getName(), qf.getOrderings()[0].getField(), 'Unexpected order field - should have been resolved from the field Birthdate');
203
+
System.assertEquals(fflib_QueryFactory.SortOrder.ASCENDING, qf.getOrderings()[0].getDirection(), 'Unexpected order direction.');
0 commit comments